支持`std :: cbegin()`在C ++ 14 [英] Support of `std::cbegin()`in C++14

查看:340
本文介绍了支持`std :: cbegin()`在C ++ 14的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Scott Mayers的有效的现代C ++项目13中可以看出,const_iterators优先于迭代器。我同意,但我也想使用非成员函数,而不是成员函数。根据书中应该有一个非成员函数 std :: cbegin() std :: cend()在C ++ 14。



为了使用这个函数,我刚刚安装了gcc版本4.9.2,并使用 -std = c ++ 14 。它似乎编译,直到我尝试使用 std :: cbegin()。我开始搜索对这个函数的支持,但没有找到任何关于它。例如,在 gnu onlinedocs状态下,该功能甚至未提及。



我的问题是, std :: cbegin() std :: cend c $ c>真的支持在c ++ 14或这是一个错误的书?如果它将是一个C ++ 14功能,是否有编译器已经支持这些功能和什么时候gcc支持它?



有很多问题,SO约 begin()但是这些问题是关于成员函数或关于constexprness,而不是关于非成员变量的支持。

这里,您可以看到


全局函数cbegin,cend,rbegin,rend,crbegin和crend用于范围访问容器,数组和初始化器列表。


已添加到GCC 5.1中。


Item 13 from Scott Mayers' "Effective Modern C++" states to prefer const_iterators over iterators. I agree but I also want to use non-member functions rather than member functions. According to the book there should be a non-member function std::cbegin() and std::cend() in C++14.

To make use of this functions I just installed gcc version 4.9.2 and compiled with the flag -std=c++14. It seems to compile until I try to use std::cbegin(). I start searching for the support for this function but couldn't find anything about it. For example, at gnu onlinedocs status the function isn't even mentioned.

My question is, will std::cbegin() and std::cend() really be supported in c++14 or is this a mistake in the book? If it will be a C++14 feature, are there compilers which already support these functions and when will gcc support it?

There are many questions at SO about begin() but these questions are about the member functions or about the constexpr-ness and not about the support of the non-member variant.

解决方案

GCC 4.9's support for C++14 is experimental and incomplete. But here, you can see that

global functions cbegin, cend, rbegin, rend, crbegin, and crend for range access to containers, arrays and initializer lists.

were added in GCC 5.1.

这篇关于支持`std :: cbegin()`在C ++ 14的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆