std::array<T,N>::end, std::array<T,N>::cend
출처: ko.cppreference.net
iterator end() noexcept;
|
(1) | (C++11부터) (C++17부터 constexpr) |
const_iterator end() const noexcept;
|
(2) | (C++11부터) (C++17부터 constexpr) |
const_iterator cend() const noexcept;
|
(3) | (C++11부터) (C++17부터 constexpr) |
마지막 요소 뒤의 요소를 가리키는 반복자를 반환합니다. array.
이 요소는 자리 표시자 역할을 합니다; 접근을 시도하면 정의되지 않은 동작이 발생합니다.
반환값
마지막 요소의 다음을 가리키는 반복자.
복잡도
상수.
예제
이 코드 실행
#include <algorithm> #include <array> #include <iomanip> #include <iostream> 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; // => 런타임 시 정의되지 않은 동작 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; // 컴파일 타임 오류: // 읽기 전용 변수에 할당할 수 없음 // 모든 요소 출력 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'; // 컴파일 타임 오류: // 읽기 전용 변수에 할당할 수 없음 }
출력:
1) true true 2) false false 3) 5 5 4) 1 5) 1 2 3 4
참고 항목
|
시작 부분에 대한 반복자를 반환함
(public member function) |
|
|
(C++11)
(C++14)
|
컨테이너나 배열의 끝에 대한 반복자를 반환함
(function template) |