cbegin is implemented as shown below:
template <class C> auto cbegin(const C& container)->decltype(std::begin(container)) { return std::begin(container);
the beginning begins as shown below.
template< class C > auto begin( C& c ) -> decltype(c.begin());
This cbegin template accepts any type of argument representing a data structure similar to a container, C, and it accesses this argument through its reference-to-const, container parameter. If C is a regular type container (for example, a std :: vector), the container will be a reference to the version constant of that container (for example, const std :: vector &). Calling the begin member (provided by C ++ 11) in the const container gives a const_iterator, and this iterator returns this template.
For example, if I used the vector as an argument to cbegin , as shown below.
std::vector<int> v1; std::cbegin(v1);
Now, let's see how the template was divided in this case, the template (class C) is displayed as a vector and the cbegin parameter (const C & container), which is calculated as const vector<int> & . Now, since the container itself is constant, it will return a constant version of the beginning of the vector.
iterator begin(); const_iterator begin() const;
SACHIN GOYAL
source share