Is something like this valid C++20 code?
#include <iostream>
template <typename T>
concept impls_decrement = requires(T it) { it.decrement(); };
template <class Derived>
struct iterator_facade {
Derived& operator--()
requires impls_decrement<Derived>
{
auto& self = static_cast<Derived&>(*this);
self.decrement();
return self;
}
};
struct my_iterator : iterator_facade<my_iterator> {
void decrement() {
std::cout << "decrement" << std::endl;
}
};
int main() {
my_iterator iter;
--iter;
return 0;
}
Adapted from vector-of-bool blog post.
With the latest version of gcc, the code works fine, but the latest version of clang gives this error:
prog.cc:25:4: error: cannot decrement value of type 'my_iterator'
--iter;
^ ~~~~
1 error generated.
Which compiler is correct?
view_interface
is specified for Ranges. – TelegonusDerived
is incomplete within CRTP definition, but not for CRTP function members instantiation. – Grochow