15static_assert(__cplusplus >= 201707);
17#include <bits/stdc++.h>
27#if __cpp_lib_three_way_comparison
28static_assert(1 <=> 2 < 0 );
29static_assert(2 <=> 1 > 0 );
30static_assert(1 <=> 1 == 0 );
32#pragma message("undefined __cpp_lib_three_way_comparison")
47 struct point {
int x, y; };
48 struct line { point a, b; };
52#if __cplusplus > 201707
53 point p1 = { .x = 1 };
61#if __cpp_aggregate_paren_init >= 201902
70 line l3 = { 1, 2, 3, 4 };
78 cout << typeid(bit_cast<double>(0));
86 auto a = make_shared<int[10]>();
87 static_assert(is_same_v<
decltype(a.get()),
int*>);
90 map<int, int> m = {{2,3}};
91#if __cplusplus > 201707 && __GNUG__ > 8
92 assert(m.contains(2));
96 vector<int> v = {11, 12, 13};
97 assert(erase_if(v, [](
int a) {
return a >= 13;}) == 1);
98 assert(v.size() == 2);
104#if __cpp_template_template_args && __GNUG__ > 8
106template <
typename ... Args>
107auto make_lambda_with_parameter_pack_capture(Args&& ... args)
109 return [... args = forward<Args>(args)] {
117#if __cplusplus >= 201709
119 auto glambda = []<
class T>(T a, auto&& b) {
return a < b; };
120 assert(glambda(1,2));
122 auto f = []<
typename ...Ts>(Ts&& ...ts) {
127 struct point {
int x, y; };
128 auto point_lambda = []<
class T=point>(T&& var) {};
129 point_lambda({1, 2});
131 #if __cpp_template_template_args && __GNUG__ > 8
132 assert(make_lambda_with_parameter_pack_capture(1,2,3)() == 6);
169template <
typename T>
requires is_integral_v<T> T
constexpr requires_demo(T a) {
return a + 1; }
177template <
typename T>
auto constexpr requires_demo(T && a)
requires is_same_v<T, double> {
return 2; }
183is_signed_v<T> || (is_unsigned_v<T> && ! is_void_v<void>)
194template <
class T>
requires requires(T a) { a / 0; }
auto constexpr what(T a) {
return 1; }
195static_assert(
what(1) == 1);
197template <
class T>
requires requires(T a) { a[0]; }
auto constexpr what(T a) {
return 2; }
198static_assert(
what(
"2") == 2);
209template <
typename T>
concept truism =
true;
211#if !__cpp_lib_concepts
214template <
class T>
concept integral = is_integral_v<T>;
224template <
integral_req_ct T>
constexpr T _inc2(T a) {
return a + 1; }
226static_assert(_inc2(1) == 2);
235 {x + 1} -> convertible_to<bool>;
236 {x * 2} -> same_as<int>;
258#if __cpp_impl_coroutine
259auto switch_to_new_thread(jthread& out)
263 bool await_ready() {
return false; }
264 void await_suspend(coroutine_handle<> h) {
265 jthread& out = *p_out;
267 throw runtime_error(
"Output jthread parameter not empty");
268 out = jthread([h] { h.resume(); });
270 void await_resume() {}
272 return awaitable{&out};
276 struct promise_type {
277 struct task get_return_object() {
return {}; }
278 suspend_never initial_suspend() {
return {}; }
279 suspend_never final_suspend() noexcept {
return {}; }
280 void return_void() {}
281 void unhandled_exception() {}
285struct task resuming_on_new_thread(jthread& out)
287 auto starting_tid = this_thread::get_id();
289 co_await switch_to_new_thread(out);
291 assert(this_thread::get_id() != starting_tid);
297 resuming_on_new_thread(out);
301#pragma message("undefined __cpp_impl_coroutine")
328 vector<int> v = {5, 7, 4, 2, 8, 6, 1, 9, 1, 3};
330 assert(v.front() <= v.back());
331 assert(ranges::distance(v));
332 assert(!ranges::distance(v.begin(), v.begin()));
337 auto data = {0, 1, 2, 3};
339#if __clang_major__ != 10
340 ranges::reverse_view rv {data};
341 auto r = data | views::reverse;
343 vector result(r.begin(), r.end());
344 assert(vector(rv.begin(), rv.end()) == result);
345 assert((result == vector{3, 2, 1, 0}));
347 auto [min, max] = ranges::minmax({3, 2, 1});
348 auto a = ranges::minmax({3, 2, 1});
351 assert(!in_range<std::size_t>(-1));
355#pragma message("undefined __cpp_lib_ranges")
358#include <experimental/source_location>
364 auto l = experimental::source_location::current();
365 basic_stringstream<char> buff;
366 buff << l.file_name() <<
":" << l.line() <<
":" << l.column() << l.function_name();
367 assert(buff.str().length());
377 auto constexpr plus_one = std::bind_front(std::plus<int>(), 1);
378 static_assert(plus_one(2) == 3);
short concept definition from a constraint directly
trivial concepts as assignment
auto to_array_demo
to_array
void location_20()
source_location
void complex_requirement_demo()
void requires_expression_demo()
Annotated example of requires-expression.
constexpr T requires_demo(T a)