Clang vs gcc std :: crbegin with boost :: iterator_range

Dan*_*iel 6 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;
}
Run Code Online (Sandbox Code Playgroud)

但是使用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> > >&
Run Code Online (Sandbox Code Playgroud)

谁是对的?

注意:Boost版本1.61

eca*_*mur 11

这是libc ++中的一个错误 ; std::crbegin委托给rbegin,但通过称之为不合格,它正在接收boost::rbegin(文件):

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

这与[iterator.range]相反,后者表示crbeginstd::rbegin仅委托给:

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

14 - 返回: std::rbegin(c).

Libc ++的实现cbegin,cend并且crend有相同的bug.

  • 感谢错误报告. (2认同)
  • 现在它已修复. (2认同)