| 1 |
#include <utility> |
| 2 |
#include <concepts> |
| 3 |
#include <string> |
| 4 |
|
| 5 |
template <typename Type> |
| 6 |
concept ConstDereferenceable = |
| 7 |
requires(Type type) |
| 8 |
{ |
| 9 |
{ *type } -> std::same_as<int const &>; |
| 10 |
// { *type } -> std::convertible_to<int const &>; |
| 11 |
}; |
| 12 |
//= |
| 13 |
|
| 14 |
template <typename Type> |
| 15 |
concept Dereferenceable = |
| 16 |
requires(Type type) |
| 17 |
{ |
| 18 |
{ *type } -> std::same_as<int &>; |
| 19 |
}; |
| 20 |
|
| 21 |
//iterable |
| 22 |
struct Iterable |
| 23 |
{ |
| 24 |
Iterable &operator++(); |
| 25 |
Iterable operator++(int); |
| 26 |
|
| 27 |
int const &operator*() const; |
| 28 |
int &operator*(); |
| 29 |
}; |
| 30 |
//= |
| 31 |
|
| 32 |
template <typename Type> |
| 33 |
concept InIterator = |
| 34 |
ConstDereferenceable<Type>; |
| 35 |
|
| 36 |
template <InIterator Type> |
| 37 |
void inFun(Type tp) |
| 38 |
{} |
| 39 |
|
| 40 |
|
| 41 |
template <typename Type> |
| 42 |
concept OutIterator = |
| 43 |
Dereferenceable<Type>; |
| 44 |
|
| 45 |
template <OutIterator Type> |
| 46 |
void outFun(Type tp) |
| 47 |
{} |
| 48 |
|
| 49 |
int main() |
| 50 |
{ |
| 51 |
inFun(Iterable{}); |
| 52 |
outFun(Iterable{}); |
| 53 |
} |