c++ - Clang 与 gcc std::crbegin with boost::iterator_range

标签 c++ gcc boost clang c++14

使用 libc++ 的 Clang 3.8.1 编译以下程序:

#include <vector>
#include <iterator>
#include <algorithm>
#include <iostream>

#include <boost/range/iterator_range.hpp>

int main()
{
    const std::vector<int> v {1, 2, 3};

    const auto range = boost::make_iterator_range(v);

    std::copy(std::crbegin(range), std::crend(range), std::ostream_iterator<int> {std::cout, " "});
    std::cout << std::endl;

    return 0;
}

但是带有 libstdc++ 的 gcc 6.1.0 没有。 gcc错误的第一行是:

error: no matching function for call to 'crbegin(const boost::iterator_range<__gnu_cxx::__normal_iterator<const int*, std::vector<int> > >&

谁是对的?

注意:Boost 版本 1.61

最佳答案

这是一个bug in libc++ ; std::crbegin正在委托(delegate)给 rbegin ,但通过称其为不合格,它正在拾取 boost::rbegin ( documentation ):

template <class _Cp>
inline _LIBCPP_INLINE_VISIBILITY
auto crbegin(const _Cp& __c) -> decltype(rbegin(__c))
{
    return rbegin(__c);
    //     ^-- unqualified, allows ADL
}

这与 [iterator.range] 相反,它表示 crbegin应该委托(delegate)给 std::rbegin仅:

template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c));

14 - Returns: std::rbegin(c).

Libc++ 对 cbegin 的实现, cendcrend有同样的错误。

关于c++ - Clang 与 gcc std::crbegin with boost::iterator_range,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38878454/

相关文章:

c++ - 用于比较复合类型映射元素的 find_if 的 lambda 函数谓词

c++ - 对象正在初始化为不需要的值

c++ - mciSendString随机停止工作

c++ - 将迭代器传递给 lambda

c++ - 即使所有文件都使用 fPIC 编译,ld 也无法将静态库链接到动态库

c++ - c++什么时候实例化方法?

c++ - 使用 boost 预处理器迭代调用可变参数模板

c++ - 为什么 g++ 从带有转换运算符和不可访问的函数调用运算符的类型中初始化 std::function<> 失败?

c++ - 使用 boost hana 检查特定的嵌套类型/标签

Centos7需要Boost-Libboost(ContexBroker)