From cppreference.com
constexprdecltype(auto)front()requiresranges::forward_range<D>; (1) (since C++20)constexprdecltype(auto)front()constrequiresranges::forward_range<constD>; (2) (since C++20)The default implementation of front() member function returns the first element in the view of the derived type. Whether the element is returned by value or by reference depends on the operator* of the iterator type.
Equivalent to return*ranges::begin(derived);, where derived is:
1)static_cast<D&>(*this)
2)static_cast<constD&>(*this)
If
is true, the behavior is undefined.
(until C++26)If
is true:
If the implementation is
, a
occurs.
If the implementation is not hardened, the behavior is undefined.
(since C++26)Return value
The first element in the view.
Notes
In C++20, no type derived from
in the standard library provides their own front() member function. Almost all of these types use the default implementation.
A notable exception is
std::ranges::basic_istream_view
. For it never satisfies
, the view cannot use the inherited front().
The inherited front() member function is available for
, but a call to it always results in undefined behavior.
Example
See also
(C++11)(C++14)
returns an iterator to the beginning of a container or array
(function template)
(C++20)
returns an iterator to the beginning of a range
(customization point object)
(C++20)
returns an iterator to the beginning of a read-only range
(customization point object)