Topic: Absence of global functions std::cbegin() and std::cend()


Author: vlad.moscow@mail.ru
Date: Tue, 17 Jan 2012 08:33:59 -0800 (PST)
Raw View
Along with global functions std::begin() and std::end() there should
be their visavis in the C++ Standard: global functions std::cbegin()
and std::cend() which return const_iterator for containers or pointers
to constant arrays.

For example

#include<iostream>
#include<algorithm>
#include<iterator>

int main()
{
    const int a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

    std::vector<int>  v( std::cbegin( a ), std::cend( a ) );

    std::copy( std::cbegin( a ), std::cend( a ),
std::ostream_iterator<int>( std::cout, " " ) );
    std::copy( std::cbegin( v ), std::cend( v ),
std::ostream_iterator<int>( std::cout, " " ) );
}


--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]