【问题标题】:Boost BCCL Container Algorithm Working ExampleBoost BCCL 容器算法工作示例
【发布时间】:2011-07-11 13:41:51
【问题描述】:

有人可以提供一个完整(包括所有头文件)工作(编译)示例,说明如何在例如 boost::RandomAccessContainer 和 std::sort?

【问题讨论】:

    标签: c++ algorithm boost containers c++-concepts


    【解决方案1】:

    文档中给出的示例有什么问题?

    当然,它并不完整,但编译它应该很简单......

    此外,您的请求无法满足:您希望对std::sort 进行概念检查,但无法重新定义此功能。您当然可以定义自己的排序函数,并使用文档提供的 BCCL 代码:

    #include <algorithm>
    
    #include "boost/concept/requires.hpp"
    
    template<typename I>
    BOOST_CONCEPT_REQUIRES(
        ((Mutable_RandomAccessIterator<I>))
        ((LessThanComparable<typename Mutable_RandomAccessIterator<I>::value_type>)),
        (void)) // return type
        sort(I begin, I end)
    {
        std::sort(begin, end);
    }
    
    int main() {
        int a[] = { 1, 4, 3, 2, 6, 5 };
        sort(a, a + 6);
    }
    

    注意:我从未使用过 BCCL。把上面的东西一起破解是微不足道的,我花了不到五分钟的时间。当然你也可以这样做?

    【讨论】:

    • 使用 GCC 4.6.1 在我的 Ubuntu 11.04 上无法编译:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-30
    • 1970-01-01
    • 2015-04-30
    • 2011-02-26
    • 2011-04-22
    • 1970-01-01
    相关资源
    最近更新 更多