除了包含于 <iterator> ,若包含下列任一头文件,则保证 std::begin 与std::cbegin 可用: <array>、 <deque>、 <forward_list>、 <list>、 、 <regex>、 <set> 、 (C++20 起)、 <string> 、 <string_view> (C++17 起)、 <unordered_map>、 <unordered_set> 及<vector>。 用户定义重载可以...
非数组重载准确地反映了C::begin的行为。如果该成员函数的实现不合理,那么就会有意外的效果。 std::cbegin是为统一成员与非成员的范围访问而引入的。参阅LWG 问题 2128。 如果C是浅 const 的视图,那么std::cbegin可能返回可变的迭代器。某些用户不期待这种行为。参阅P2276与P2278。 示例 参阅...
std::begin,std::cbegin 定义于头文件<array> 定义于头文件<deque> 定义于头文件<forward_list> 定义于头文件<iterator> 定义于头文件<list> 定义于头文件 定义于头文件<regex> 定义于头文件<set> 定义于头文件 (C++20 起) 定义于头文件<string> 定义于头文件<...
名字ranges::cbegin 代表一个定制点对象,它是字面 semiregular 类类型(为说明目的以 cbegin_ftor 表示)的 const 函数对象。cbegin_ftor 的所有实例均相等。从而能自由地复制 ranges::cbegin ,且能交替使用其副本。 给定类型集合 Args... ,若 std::declval<Args>()... 满足上面对于 ranges::cbegin 的参数...
const_local_iterator cbegin( size_type n ) const; (since C++11) 将迭代器返回到存储桶的第一个元素(带索引)。n... 参数 n - the index of the bucket to access 返回值 第一个元素的迭代器。 复杂性 常量。 另见 end(int) cend(int) ...
const_iterator cbegin() const noexcept; (C++11 起) 返回指向 set 首元素的迭代器。 若set 为空,则返回的迭代器将等于 end()。 参数 (无) 返回值 指向首元素的迭代器。 复杂度 常数。 注意 因为iterator 和const_iterator 都是常迭代器(而且实际上可以是同一类型),故不可能通过任何这些成员函数返回的迭...
#include<string>#include<iostream>intmain(){std::strings("Exemplar");*s.begin()='e';std::cout<<s<<'\n';auto i=s.cbegin();std::cout<<*i<<'\n';// *i = 'E'; // error: i is a constant iterator} 二次 产出: 二次 ...
#include <string> #include <iostream> int main() { std::string s("Exemplar"); *s.begin() = 'e'; std::cout << s <<'\n'; auto i = s.cbegin(); std::cout << *i << '\n'; // *i = 'E'; // 错误: i 是常迭代器 } 输出: exemplar e参阅...
, if std::declval<Args>()... meet the requirements for arguments to ranges::cbegin above, __cbegin_fn models std::invocable<__cbegin_fn, Args...>, std::invocable<const __cbegin_fn, Args...>, std::invocable<__cbegin_fn&, Args...>, and std::invocable<const __cbegin_fn&,...
libc++ 将 cbegin() 向后移植到 C++98 模式。示例运行此代码 #include <algorithm> #include <iostream> #include <numeric> #include <string> #include <deque> int main() { std::deque<int> nums{1, 2, 4, 8, 16}; std::deque<std::string> fruits{"orange", "apple", "raspberry"}; std:...