Przejdź do głównej zawartości

C++ named requirements: LegacyBidirectionalIterator

A LegacyBidirectionalIterator is a LegacyForwardIterator that can be moved in both directions (i.e. incremented and decremented).

If a LegacyBidirectionalIterator it originates from a Container, 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

And, given

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 dereferenceable --(++a) == a
If --a == --b then a == b
a and --a designate the same iterator object
a--convertible to const It&It temp = a; --a; return temp;
*a--reference

A mutable LegacyBidirectionalIterator is a LegacyBidirectionalIterator that additionally satisfies the LegacyOutputIterator 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 (od C++20)

Click to expand

For the definition of std::iterator_traits, the following exposition-only concept is defined.

template<class I>
concept __LegacyBidirectionalIterator =
__LegacyForwardIterator<I> && requires(I i)
{
{ --i } -> std::same_as<I&>;
{ i-- } -> std::convertible_to<const I&>;
{ *i-- } -> std::same_as<std::iter_reference_t<I>>;
};

where the exposition-only concept __LegacyIterator is described in LegacyIterator#Concept.

Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DRApplied toBehavior as publishedCorrect behavior
LWG 299 (N3066)C++98the return type of *a-- was required to be convertible to Tthe return type is required to be reference
LWG 383C++98b was required to be dereferenceable after --aa is required to be dereferenceable instead

C++ named requirements: LegacyBidirectionalIterator

A LegacyBidirectionalIterator is a LegacyForwardIterator that can be moved in both directions (i.e. incremented and decremented).

If a LegacyBidirectionalIterator it originates from a Container, 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

And, given

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 dereferenceable --(++a) == a
If --a == --b then a == b
a and --a designate the same iterator object
a--convertible to const It&It temp = a; --a; return temp;
*a--reference

A mutable LegacyBidirectionalIterator is a LegacyBidirectionalIterator that additionally satisfies the LegacyOutputIterator 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 (od C++20)

Click to expand

For the definition of std::iterator_traits, the following exposition-only concept is defined.

template<class I>
concept __LegacyBidirectionalIterator =
__LegacyForwardIterator<I> && requires(I i)
{
{ --i } -> std::same_as<I&>;
{ i-- } -> std::convertible_to<const I&>;
{ *i-- } -> std::same_as<std::iter_reference_t<I>>;
};

where the exposition-only concept __LegacyIterator is described in LegacyIterator#Concept.

Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DRApplied toBehavior as publishedCorrect behavior
LWG 299 (N3066)C++98the return type of *a-- was required to be convertible to Tthe return type is required to be reference
LWG 383C++98b was required to be dereferenceable after --aa is required to be dereferenceable instead