top of page
  • Joseph

Type Manipulation in C++

Updated: Nov 9, 2022

C++ standard library has simple functions to manipulate types. The following example shows how we can find the type of a variable and create new types using that.

int main() { const double A = 10; using A_type = decltype(A); // find the type of variable A using A_ptr_type = std::add_pointer<A_type>::type; // A_ptr_type will be double * A_ptr_type A_ptr = &A; using B_type = std::remove_pointer<decltype(A_ptr)>::type; // B_type will be double B_type B = 2.0; }

5 views0 comments

Recent Posts

See All

We can use variadic arguments to create variadic data structures in C++. template<typename ... T> struct DS{}; template<typename T, typename ... Args> struct DS<T, Args ...> { T first; DS<Arg

Constexpr is a keyword that declares that the value of a variable or a function is declared at compile time. Similar to the const keyword a compiler error is raised when any code attempts to modify th

A fold expression is an instruction for the compiler to repeat the application of an operator over a parameter pack. This is especially useful when you need to apply the same operator to a set of argu

bottom of page