加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – Clang vs gcc std :: crbegin with boost :: iterator_rang

发布时间:2020-12-16 03:19:02 所属栏目:百科 来源:网络整理
导读:带有libc的Clang 3.8.1编译以下程序: #include vector#include iterator#include algorithm#include iostream#include boost/range/iterator_range.hppint main(){ const std::vectorint v {1,2,3}; const auto range = boost::make_iterator_range(v); std
带有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委托给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只应委托给std :: rbegin:

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

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

Libc的cbegin,cend和crend的实现也有同样的bug.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读