使用 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
的实现, cend
和 crend
有同样的错误。
关于c++ - Clang 与 gcc std::crbegin with boost::iterator_range,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38878454/