C++ features by examples
Collaboration diagram for Language:

Classes

struct  Base11
 
struct  Derived11
 

Functions

void types_11 ()
 
void unique_pounter ()
 unique_ptr More...
 
void shared_pointer ()
 shared_ptr More...
 
void weak_pointer ()
 weak_ptr More...
 
void dynamic_memory_11 ()
 
char func_type (const int &x)
 
char func_type (int &x)
 
char func_type (int &&x)
 
template<class T >
char func_type_template (T &&x)
 Forwarding reference More...
 
void references_11 ()
 
void init_11 ()
 
auto trailing_return_type (int a) -> int
 
void copy_elision_demo ()
 copy_elision More...
 
void func_11 ()
 
constexpr int constexpr_factorial (int n)
 https://en.cppreference.com/w/cpp/language/constexpr More...
 
template<typename T >
constexpr T adder (T v)
 https://en.cppreference.com/w/cpp/language/parameter_pack More...
 
template<typename T , typename... Args>
constexpr T adder (T first, Args... args)
 

Variables

auto auto_int = 1
 https://en.cppreference.com/w/cpp/language/auto More...
 

Detailed Description

Function Documentation

◆ adder() [1/2]

template<typename T , typename... Args>
constexpr T adder ( first,
Args...  args 
)
constexpr

Definition at line 323 of file 11.cpp.

323 {
324 return first + adder(args...);
325}
constexpr T adder(T v)
https://en.cppreference.com/w/cpp/language/parameter_pack
Definition: 11.cpp:318
Here is the call graph for this function:

◆ adder() [2/2]

template<typename T >
constexpr T adder ( v)
constexpr

https://en.cppreference.com/w/cpp/language/parameter_pack

Definition at line 318 of file 11.cpp.

318 {
319 return v;
320}
Here is the caller graph for this function:

◆ constexpr_factorial()

constexpr int constexpr_factorial ( int  n)
constexpr

https://en.cppreference.com/w/cpp/language/constexpr

Definition at line 310 of file 11.cpp.

311{
312 return n <= 1 ? 1 : (n * constexpr_factorial(n - 1));
313}
constexpr int constexpr_factorial(int n)
https://en.cppreference.com/w/cpp/language/constexpr
Definition: 11.cpp:310
Here is the call graph for this function:
Here is the caller graph for this function:

◆ copy_elision_demo()

void copy_elision_demo ( )

copy_elision

Definition at line 275 of file 11.cpp.

276{
277 struct Obj2 { Obj2* orig = this; int ballast[4]; };
278 auto&& o2 = [](){ return Obj2();}();
279 assert(&o2 == o2.orig);
280}

◆ dynamic_memory_11()

void dynamic_memory_11 ( )

new,

delete

Definition at line 126 of file 11.cpp.

127{
128 auto a = new int[3] {1, 2, 3};
129 assert(a[2] == 3);
130 delete[] a;
131
132 auto as = new string[3] {"1", "2", "3"};
133 assert(as[2] == "3");
134 delete[] as; // calls destructors for all members
135
137
139
140 weak_pointer();
141}
void shared_pointer()
shared_ptr
Definition: 11.cpp:86
void weak_pointer()
weak_ptr
Definition: 11.cpp:109
void unique_pounter()
unique_ptr
Definition: 11.cpp:54
Here is the call graph for this function:
Here is the caller graph for this function:

◆ func_11()

void func_11 ( )

Definition at line 282 of file 11.cpp.

283{
284 class functor {
285 int y = 1;
286 public:
287 int operator()(int a) const {
288 return a + y;
289 }
290 };
291 functor ft;
292 assert(ft(1) == 2);
293
294 // https://en.cppreference.com/w/cpp/utility/functional/function
295 function<int(int)> ft2 = ft;
296 assert(ft(2) == 3);
297 return;
298
299 // https://en.cppreference.com/w/cpp/utility/functional/bind
300 auto binded = bind(ft2, 3);
301 assert(binded() == 5);
302
304}
void copy_elision_demo()
copy_elision
Definition: 11.cpp:275
Here is the caller graph for this function:

◆ func_type() [1/3]

char func_type ( const int &  x)

func_type - overloaded functions remove_reference

Definition at line 146 of file 11.cpp.

147{
148 assert(is_const<typename remove_reference<decltype(x)>::type>::value);
149 assert(is_lvalue_reference<decltype(x)>::value);
150 return 'C';
151}
Here is the caller graph for this function:

◆ func_type() [2/3]

char func_type ( int &&  x)

Definition at line 159 of file 11.cpp.

160{