diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2023-07-24 15:00:59 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2023-07-24 16:28:33 +0200 |
commit | ff0507d6db02b9fc43e621d51b73419018bb38c8 (patch) | |
tree | 5d52c19711bce7b98c950ed7e446f653bb7e1dfb /a1/hello-cpp20.cc | |
parent | e40fd395aa354d0d8ea79dbae899fd8346adc8dc (diff) |
A1: c++20 variation and report.
Diffstat (limited to 'a1/hello-cpp20.cc')
-rw-r--r-- | a1/hello-cpp20.cc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/a1/hello-cpp20.cc b/a1/hello-cpp20.cc new file mode 100644 index 0000000..76b2bbd --- /dev/null +++ b/a1/hello-cpp20.cc @@ -0,0 +1,21 @@ +import <iostream>; +import <string>; + +template<typename T> +concept Printable = requires(T a) { std::cout << a; }; + +void printIt(const Printable auto& p) +{ + std::cout << p; +} + +struct MyType {}; + +int main() +{ + using namespace std::string_literals; + printIt("Hello Modern World!\n"); // ok, const char* string is printable + printIt("Hello Modern World!\n"s); // ok, std::string literal is printable + printIt(42); // ok, int is printable + // printIt(MyType{}); // error: doesn't adhere to Printable concept +} |