I recently learned about c++ concepts and I am trying to understand them better. Here is the concept of an std::input_or_output_iterator
from cppreference.
template <class I>
concept input_or_output_iterator =
requires(I i) {
{ *i } -> /*can-reference*/;
} &&
std::weakly_incrementable<I>;
I think I understand the {*i}
part which means that the every i
which satisfies the concept has to be able to dereference. However, what is the point of the -> /*can-reference*/
? What is meant by The exposition-only concept and also isn't this the same as
template <class I>
concept input_or_output_iterator =
requires(I i) {
{ *i };
} &&
std::weakly_incrementable<I>;
or as
concept input_or_output_iterator =
requires(I i) {
*i ;
} &&
std::weakly_incrementable<I>;
?
Actually, I tried it on MSVC compiler and
template <class I>
concept foo = requires(I i) {
{*i};
};
or
template <class I>
concept foo = requires(I i) {
*i;
};
does compile but
template <class I>
concept bar = requires(I i) {
{*i} -> /*can-reference*/;
};
does not.