non-const container: iterator begin(); returns a mutable iterator.
Using the iterator returned by begin(), the elements in the container can be modified.
const container: const_iterator begin() const ; returns a non-mutable iterator
Using the iterator returned by begin(), the elements in the container can be accessed, but not modified.
struct B
{
using iterator = int* ;
// this is not const-correct
iterator begin() const { return data ; }
iterator end() const { return data+N ; }
staticconstexpr std::size_t N = 6 ;
int arr[N] { 0, 1, 2, 3, 4, 5 } ;
int* data = arr ;
};
void not_const_correct( const B& b )
{
auto iter = b.begin() ;
std::cout << *iter << '\n' ; // fine
*iter = 100 ; // compiles cleanly: but this is terrible
// a const object is being modified
}