summaryrefslogtreecommitdiff
path: root/a1/hello-cpp20.cc
diff options
context:
space:
mode:
Diffstat (limited to 'a1/hello-cpp20.cc')
-rw-r--r--a1/hello-cpp20.cc21
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
+}