yo/advancedtemplates/concepts/examples/type.cc
raw| 1 | #include <string> |
| 2 | #include <iostream> |
| 3 | #include <queue> |
| 4 | |
| 5 | //type |
| 6 | template <typename Type> |
| 7 | concept Iteratable = |
| 8 | requires(Type tp) |
| 9 | { |
| 10 | typename Type::iterator; |
| 11 | tp.begin(); |
| 12 | }; |
| 13 | |
| 14 | template <Iteratable Type> |
| 15 | auto iter(Type const &obj) |
| 16 | { |
| 17 | return obj.begin(); |
| 18 | } |
| 19 | //= |
| 20 | |
| 21 | using namespace std; |
| 22 | |
| 23 | int main() |
| 24 | { |
| 25 | string str; |
| 26 | cout << *iter(str); |
| 27 | |
| 28 | iter(queue<int>{}); |
| 29 | } |