C++ features by examples

language More...

Collaboration diagram for Language:

Modules

 Folding
 fold
 
 Qualified nested namespace
 namespace
 
 Structured bindings
 
 New attributes
 fallthrough, nodiscard, maybe_unused
 

Functions

void references_17 ()
 
void conditional_with_init ()
 
constexpr int const_if ()
 if More...
 
void types_17 ()
 

Variables

static char char_u8 = u8'x'
 character_literal More...
 

Detailed Description

language

Function Documentation

◆ conditional_with_init()

void conditional_with_init ( )

Variable declaration in conditionals

Specs: if, switch

Definition at line 353 of file 17.cpp.

354{
355 if (auto a = true) {
356 };
357
358 switch (int a = 10) {
359 }
360}

◆ const_if()

constexpr int const_if ( )
constexpr

if

Definition at line 396 of file 17.cpp.

397{
398 if constexpr(true)
399 return 1;
400}

◆ references_17()

void references_17 ( )

Definition at line 256 of file 17.cpp.

257{
258 static_assert(is_reference_v<int&>);
259
260 // L-value:
261 static_assert(is_lvalue_reference_v<int&>);
262
263 // R-value
264 static_assert(is_rvalue_reference_v<int&&>);
265}
Here is the caller graph for this function:

◆ types_17()

void types_17 ( )

Direct list initialization of enums

floating_literal

invoke

Definition at line 420 of file 17.cpp.

421{
422 enum byte_e : unsigned char {};
423 static byte_e b { 123 };
424
425floating_literal:
426 static_assert(is_integral_v<int>);
427 static_assert(__cpp_hex_float);
428 double hex_double = 0x1.2p3;
429 assert(hex_double == 9.0);
430
431 static_assert(is_invocable<decltype(types_17)>::value);
432 static_assert(is_invocable<int()>::value);
433 static_assert(is_invocable_r<int, int()>::value);
434 static_assert(is_invocable_r<void, void(int), int>::value);
435 static_assert(negation_v<bool_constant<false>>);
436
437 auto inc = [](int a) -> int { return a + 1; };
438 static_assert(is_invocable_r<int, decltype(inc), int>::value);
439 static_assert(__cpp_lib_invoke);
440 assert(invoke(inc, 2) == 3);
441}
constexpr int(* inc)(int)
Definition: 17.cpp:174
void types_17()
Definition: 17.cpp:420
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ char_u8

char char_u8 = u8'x'
static

character_literal

Character literal

Definition at line 410 of file 17.cpp.