C++ features by examples
Collaboration diagram for Language:

Namespaces

namespace  lambda
 

Functions

void init_20 ()
 
void types_20 ()
 
void dynamic_memory_20 ()
 

Variables

auto to_array_demo = to_array("foo")
 to_array More...
 

Detailed Description

language

Function Documentation

◆ dynamic_memory_20()

void dynamic_memory_20 ( )

Shared array make_shared

contains

Definition at line 82 of file 20.cpp.

83{
86 auto a = make_shared<int[10]>();
87 static_assert(is_same_v<decltype(a.get()), int*>);
88
90 map<int, int> m = {{2,3}};
91#if __cplusplus > 201707 && __GNUG__ > 8
92 assert(m.contains(2));
93#endif
94#if __cpp_lib_erase_if
96 vector<int> v = {11, 12, 13};
97 assert(erase_if(v, [](int a) {return a >= 13;}) == 1);
98 assert(v.size() == 2);
99#endif
100}
Here is the caller graph for this function:

◆ init_20()

void init_20 ( )

Definition at line 45 of file 20.cpp.

46{
47 struct point { int x, y; };
48 struct line { point a, b; };
49
50 // [aggregate_initialization](https://en.cppreference.com/w/cpp/language/aggregate_initialization)
51
52#if __cplusplus > 201707
53 point p1 = { .x = 1 };
54 assert(p1.x == 1);
55 assert(!p1.y);
56
57 point p2 { {} , 2 };
58 assert(p2.y == 2);
59 assert(!p2.x);
60#endif
61#if __cpp_aggregate_paren_init >= 201902
62 int a[] (0, 1, 2);
63 assert(a[2] == 2);
64 line l2 = { 1, 2 };
65 assert(l2.a.x == 1);
66 assert(l2.a.y == 2);
67#endif
68 line l1 = { };
69 assert(!l1.a.x);
70 line l3 = { 1, 2, 3, 4 };
71 assert(l3.b.x == 3);
72 assert(l3.b.y == 4);
73}
Here is the caller graph for this function:

◆ types_20()

void types_20 ( )

Definition at line 75 of file 20.cpp.

76{
77#if __cpp_lib_bit_cast
78 cout << typeid(bit_cast<double>(0));
79#endif
80}
Here is the caller graph for this function:

Variable Documentation

◆ to_array_demo

auto to_array_demo = to_array("foo")

to_array

Definition at line 42 of file 20.cpp.