Namespaces
Variants
Actions

std::forward_list<T,Allocator>::begin, std::forward_list<T,Allocator>::cbegin

From cppreference.com
 
 
 
 
iterator begin() noexcept;
(1) (since C++11)
(constexpr since C++26)
const_iterator begin() const noexcept;
(2) (since C++11)
(constexpr since C++26)
const_iterator cbegin() const noexcept;
(3) (since C++11)
(constexpr since C++26)

Returns an iterator to the first element of *this.

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

range-begin-end.svg

Contents

[edit] Return value

Iterator to the first element.

[edit] Complexity

Constant.

[edit] Example

#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <forward_list>
 
int main()
{
    std::forward_list<int> nums{1, 2, 4, 8, 16};
    std::forward_list<std::string> fruits{"orange", "apple", "raspberry"};
    std::forward_list<char> empty;
 
    // Print forward_list.
    std::for_each(nums.begin(), nums.end(), [](const int n) { std::cout << n << ' '; });