Boost BCCL容器算法实例

Boost BCCL Container Algorithm Working Example

本文关键字:算法 实例 BCCL Boost      更新时间:2023-10-16

是否有人给出一个完整的(包括所有头文件)工作(编译)如何使用Boost BCCL的例子,例如一个boost::RandomAccessContainer与std::sort在一起?

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

当然,它不完整,但它应该是微不足道的编译…

更进一步,你的请求不能被满足:你想要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。将上述内容整合在一起很简单,花了我不到五分钟的时间。当然你也可以这么做?