From cppreference.com
A
is a
that can be moved in both directions (i.e. incremented and decremented).
If a
it originates from a
, then it's value_type is the same as the container's, so dereferencing (*it) obtains the container's value_type.
Requirements
The type It satisfies LegacyBidirectionalIterator if
The type It satisfies
And, given
a and b, lvalues of type It
reference, the type denoted by std::iterator_traits<It>::reference
The following expressions must be valid and have their specified effects:
ExpressionReturnEquivalent expressionNotes --aIt&Preconditions: a is decrementable (there exists such b that a==++b)
Postconditions:
a is
--(++a)==a
If --a==--b then a==b
a and --a designate the same iterator object
a--convertible to constIt&Ittemp=a;--a;returntemp;*a--referenceA mutableLegacyBidirectionalIterator is a LegacyBidirectionalIterator that additionally satisfies the
requirements.
Notes
The begin iterator is not decrementable and the behavior is undefined if --container.begin() is evaluated.
A bidirectional iterator does not have to be dereferenceable to be decrementable (in particular, the end iterator is not dereferenceable but is decrementable).
Concept
For the definition of
, the following exposition-only concept is defined.
template<classI>concept__LegacyBidirectionalIterator=__LegacyForwardIterator<I>&&requires(Ii){{--i}->std::same_as<I&>;{i--}->std::convertible_to<constI&>;{*i--}->std::same_as<std::iter_reference_t<I>>;};where the exposition-only concept __LegacyForwardIterator is described in
.
(since C++20)Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior
(
) C++98 the return type of *a-- was
required to be convertible to Tchanged the return
type to reference
C++98 b was required to be dereferenceable after --aa is required to be dereferenceable instead
(
) C++98 the return type of *a-- did not match the return
type of *a++ required by
changed the return
type to reference
This issue was initially resolved by
(iterator concepts), which was dropped later from the C++ standard.
See also