yo/advancedtemplates/concepts/examples/add.cc
raw| 1 | #include <string> |
| 2 | #include <iostream> |
| 3 | |
| 4 | using namespace std; |
| 5 | |
| 6 | template <typename Type> |
| 7 | concept Add = |
| 8 | requires(Type lhs, Type rhs) |
| 9 | { |
| 10 | lhs + rhs; |
| 11 | }; |
| 12 | |
| 13 | template <Add Type> |
| 14 | Type add(Type const &lhs, Type const &rhs) |
| 15 | { |
| 16 | return lhs + rhs; |
| 17 | } |
| 18 | |
| 19 | int main() |
| 20 | { |
| 21 | add(1, 2); |
| 22 | add("s1"s, "s2"s); |
| 23 | |
| 24 | add(cout, cerr); |
| 25 | } |