GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::array::begin,std::array::cbegin(3) C++ Standard Libary std::array::begin,std::array::cbegin(3)

std::array::begin,std::array::cbegin - std::array::begin,std::array::cbegin


iterator begin() noexcept; (until C++17)
constexpr iterator begin() noexcept; (since C++17)
const_iterator begin() const noexcept; (until C++17)
constexpr const_iterator begin() const noexcept; (since C++17)
const_iterator cbegin() const noexcept; (until C++17)
constexpr const_iterator cbegin() const noexcept; (since C++17)


Returns an iterator to the first element of the array.


If the array is empty, the returned iterator will be equal to end().


range-begin-end.svg


(none)


Iterator to the first element.


Constant.

// Run this code


#include <array>
#include <iostream>
#include <algorithm>
#include <iomanip>


int main()
{
std::cout << std::boolalpha;


std::array<int, 0> empty;
std::cout << "1) "
<< (empty.begin() == empty.end()) << ' ' // true
<< (empty.cbegin() == empty.cend()) << '\n'; // true
// *(empty.begin()) = 42; // => undefined behaviour at run-time


std::array<int, 4> numbers{5, 2, 3, 4};
std::cout << "2) "
<< (numbers.begin() == numbers.end()) << ' ' // false
<< (numbers.cbegin() == numbers.cend()) << '\n' // false
<< "3) "
<< *(numbers.begin()) << ' ' // 5
<< *(numbers.cbegin()) << '\n'; // 5


*numbers.begin() = 1;
std::cout << "4) " << *(numbers.begin()) << '\n'; // 1
// *(numbers.cbegin()) = 42; // compile-time error:
// read-only variable is not assignable


// print out all elements
std::cout << "5) ";
std::for_each(numbers.cbegin(), numbers.cend(), [](int x) {
std::cout << x << ' ';
});
std::cout << '\n';


constexpr std::array constants{'A', 'B', 'C'};
static_assert(constants.begin() != constants.end()); // OK
static_assert(constants.cbegin() != constants.cend()); // OK
static_assert(*constants.begin() == 'A'); // OK
static_assert(*constants.cbegin() == 'A'); // OK
// *constants.begin() = 'Z'; // compile-time error:
// read-only variable is not assignable
}


1) true true
2) false false
3) 5 5
4) 1
5) 1 2 3 4


end returns an iterator to the end
cend (public member function)
(C++11)
begin
cbegin returns an iterator to the beginning of a container or array
(C++11) (function template)
(C++14)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.