C++
In our last post, we learnt about the type trait std::is_trivial<T>. Today, let us go through another type trait that is quite similar. The expression is_standard_layout<T>::value returns true if the layout of objects of type T is compiler independent, and hence is of standard format. Else, it returns false. This is important if we create objects […]
Today let us try to understand the type trait std::is_trivial<T>. This trait checks if the given type is a trivial type. For a precise definition of what trivial means, please visit the official page. As usual, we will go through three cases: – Primitive types – Classes without inheritance – Classes involving inheritance Case-1: Primitive […]
The type trait is_convertible<From, To> checks if an object of type From can be “implicitly” converted to an object of type To. The expression is_convertible<From, To>::value returns true if implicit conversion is possible, else it returns false. For more details, please check out the reference. Let us look at three primary cases. Case-1: Pre-defined Types […]
In the last article, we looked at the std:is_base_of<T1, T2> type trait. One question that a reader asked since that article appeared is “How does is_base_of<> differ from the dynamic_cast<> operator?” Good question! In today’s post let me try to address the key differences between the two. I am not going to cover the dynamic_cast<> […]
In our on-going series on C++ Type Traits, today’s topic is about the trait std::is_base_of<>. For the official description, see this. std::is_base_of<A, B>::value takes two arguments, both classes (or structs), and returns true if A is a base class of B and false otherwise. Trivially, std::<A, A>::value is true. Let us look at an example […]
In today’s post, I would like to go over the type trait std::common_type<>. This trait was introduced in C++11. As per the specification, std::common_type<T1, T2, …Tn>::type refers to a type Tx in the given list, which the rest of the types in the list can be implicitly converted to. This works with built-in as well […]
In the previous post, we looked at the std::is_destructible<T> type trait. Today, let us try to understand another type trait std::is_empty<T>. As per the specification, is_empty<T>::value will return true in the following cases: – The class/struct has no non-static data member – The class/struct does not define a virtual function – The class/struct does not […]
In the last article, I explained the deleted destructor in some detail. Today, I would like to talk about a related construct, a type trait called std::is_destructible. Type traits, defined in the header <type_traits>, are a big help when it comes to implementing template metaprogramming. See this article for a nice introduction to type traits in […]
Since C++ 11, we can use the keyword delete to declare functions as deleted and thus prohibit the use of these functions in the code. See this article for a brief overview. In particular, the destructor of a class/struct/union can be declared as deleted. In today’s article, I am going to discuss this specific feature in […]
Title: C++ Concurrency in Action Author: Anthony Williams Publisher: Manning Publications Co. Year: 2019 (Second Edition) The first edition of this book came out in the year 2012 and covered the concurrency features of C++ 11. Much has happened since then. The present C++17 is significantly richer in terms of concurrency support, especially in […]
Recent Comments