【发布时间】:2016-12-17 03:15:23
【问题描述】:
带有 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 版
【问题讨论】:
-
gcc 给出什么错误?
-
@aschepler 我已经添加了错误的第一行 - 其余的并没有增加太多。
std::crend也一样。我实际上认为 gcc 在这里是正确的 -boost::iterator_range中没有rbegin或rend成员方法。我只是不太明白 Clang 是如何制作的! -
@Daniel :您是在使用带有 libc++ 或 libstdc++ 的 Clang 吗?如果是前者,如果不存在
rbegin成员函数,它大概会调用std::make_reverse_iterator(range.begin())。如果是后者,那确实是个好问题…… -
@ildjarn libc++。这也是我的怀疑,但这是正确的行为吗?
-
@Daniel:我不知道,但如果这是您真正的问题,那么您需要在此处进行认真的编辑以反映这一点(可能还有
language-lawyer标签)。即,您的问题目前似乎是在询问 GCC,但您真正的问题是关于 libc++。