From ff0507d6db02b9fc43e621d51b73419018bb38c8 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Mon, 24 Jul 2023 15:00:59 +0200 Subject: A1: c++20 variation and report. --- a1/hello-cpp20.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 a1/hello-cpp20.cc (limited to 'a1/hello-cpp20.cc') 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 ; +import ; + +template +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 +} -- cgit v1.2.3