Book Image

Expert C++ - Second Edition

By : Marcelo Guerra Hahn, Araks Tigranyan, John Asatryan, Vardan Grigoryan, Shunguang Wu
5 (1)
Book Image

Expert C++ - Second Edition

5 (1)
By: Marcelo Guerra Hahn, Araks Tigranyan, John Asatryan, Vardan Grigoryan, Shunguang Wu

Overview of this book

Are you an experienced C++ developer eager to take your skills to the next level? This updated edition of Expert C++ is tailored to propel you toward your goals. This book takes you on a journey of building C++ applications while exploring advanced techniques beyond object-oriented programming. Along the way, you'll get to grips with designing templates, including template metaprogramming, and delve into memory management and smart pointers. Once you have a solid grasp of these foundational concepts, you'll advance to more advanced topics such as data structures with STL containers and explore advanced data structures with C++. Additionally, the book covers essential aspects like functional programming, concurrency, and multithreading, and designing concurrent data structures. It also offers insights into designing world-ready applications, incorporating design patterns, and addressing networking and security concerns. Finally, it adds to your knowledge of debugging and testing and large-scale application design. With Expert C++ as your guide, you'll be empowered to push the boundaries of your C++ expertise and unlock new possibilities in software development.
Table of Contents (24 chapters)
1
Part 1:Under the Hood of C++ Programming
7
Part 2: Designing Robust and Efficient Applications
18
Part 3:C++ in the AI World

Type trait implementation

To understand type traits, we’ll look at the classic implementations of boost::is_void and boost::is_pointer.

boost::is_void

First, let’s look at one of the simplest traits classes, the is_void trait, which was created by Boost. It defines a generic template that’s used to implement the default behavior; that is, accept a void type, but not anything else. Hence, we have is_void::value = false:

//primary class template is_voidtemplate< typename T >
struct is_void{
static const bool value = false; //default value=false
};

Then, we fully specialize it for the void type, like so:

//"<>" means a full specialization of template class is_voidtemplate<>
struct is_void< void >{ //fully specialization for void
static const bool value = true; //only true for void type
};

Thus, we have a complete traits type that can be used to detect whether any given type, T, is void by checking the following expression...