summaryrefslogtreecommitdiff
path: root/a1/hello-cpp20.cc
blob: 76b2bbd6a906311747f3da95f9b809c3622a2aa1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
}