添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
冷冷的麦片  ·  Learn LaTeX in 30 ...·  2 周前    · 
逆袭的小笼包  ·  Ant ...·  1 月前    · 
俊逸的斑马  ·  Begin-Latex-in-minutes ...·  1 月前    · 
曾深爱过的沙滩裤  ·  Centreon Poller - ...·  10 月前    · 
叛逆的领结  ·  Home · cdk-team/CDK ...·  12 月前    · 
Filesystem library (C++17) Regular expressions library (C++11) Concurrency support library (C++11) Technical specifications Symbols index External libraries
[edit]
Iterator library

constexpr auto cbegin ( const C & c ) noexcept ( /* see below */ )
- > decltype ( std :: begin ( c ) ) ;

Returns an iterator to the beginning of the given range.

1,2) Returns c. begin ( ) , which is typically an iterator to the beginning of the sequence represented by c .
1) If C is a standard Container , returns a C::iterator object.
2) If C is a standard Container , returns a C::const_iterator object.
3) Returns a pointer to the beginning of array .
4) Returns std :: begin ( c ) , with c always treated as const-qualified.
If C is a standard Container , returns a C::const_iterator object.

[ edit ] Exceptions

4)
noexcept specification:
noexcept ( noexcept ( std :: begin ( c ) ) )

[ edit ] Overloads

Custom overloads of begin may be provided for classes and enumerations that do not expose a suitable begin() member function, yet can be iterated. The following overloads are already provided by the standard library:

[ edit ] Notes

The non-array overloads exactly reflect the behavior of C::begin . Their effects may be surprising if the member function does not have a reasonable implementation.

std::cbegin is introduced for unification of member and non-member range accesses. See also LWG issue 2128 .

If C is a shallow-const view, std::cbegin may return a mutable iterator. Such behavior is unexpected for some users. See also P2276 and P2278 .

[ edit ] Example

#include <iostream>
#include <iterator>
#include <vector>
int main() 
    std::vector<int> v = {3, 1, 4};
    auto vi = std::begin(v);
    std::cout << std::showpos << *vi << '\n'; 
    int a[] = {-5, 10, 15};
    auto ai = std::begin(a);
    std::cout << *ai << '\n';

Output:

[edit] See also

Iterator concepts
(C++20)
Iterator primitives
(deprecated in C++17)
Indirect callable concepts
Common algorithm requirements
(C++20)
(C++20)
(C++20)
Utilities
(C++20)
make_move_iterator
(C++11)
(since C++14) range-based for loop support
(function) [edit]
range-based for loop support
(function) [edit]

Similar to the use of swap (described in Swappable ), typical use of the begin function in generic context is an equivalent of using std :: begin ; begin ( arg ) ; , which allows both the ADL -selected overloads for user-defined types and the standard library function templates to appear in the same overload set.

template<typename Container, typename Function>
void for_each(Container&& cont, Function f)
    using std::begin;
    auto it = begin(cont);
    using std::end;
    auto end_it = end(cont);
    while (it != end_it)
        f(*it);
        ++it;

Overloads of begin found by argument-dependent lookup can be used to customize the behavior of std::ranges::begin, std::ranges::cbegin, and other customization pointer objects depending on std::ranges::begin.

(since C++20)
(C++11) (C++14)
returns an iterator to the end of a container or array
(function template) [edit]
returns an iterator to the beginning of a range
(customization point object) [edit]
returns an iterator to the beginning of a read-only range
(customization point object) [edit] Retrieved from " https://en.cppreference.com/mwiki/index.php?title=cpp/iterator/begin&oldid=169874 "
Toolbox
  • What links here
  • Related changes
  • Upload file
  • Special pages
  • Printable version
  • Page information
    • In other languages
  • Deutsch
  • Español
  • Français
  • Italiano
  • 日本語
  • Português
  • Русский
  • 中文
  •