The std::remove_const template of C++ STL is present in the <type_traits> header file. The std::remove_const template of C++ STL is used to get the type T without const qualification. It return the boolean value true if T is without const qualified, otherwise return false. Below is the syntax for the same:
Header File:
#include<type_traits>
Template Class:
template <class T> struct remove_const;
Syntax:
std::remove_const<T>::value
Parameter: This template std::remove_const accepts a single parameter T(Trait class) to check whether T is without const qualified or not.
Return Value: The template std::remove_const returns a boolean value:
- True: If type T is without const qualified.
- False: If type T is with const qualified.
Below is the program to demonstrate std::remove_const in C++:
Program:
// C++ program to illustrate // std::remove_const #include <bits/stdc++.h> #include <type_traits> using namespace std; // Driver Code int main() { // Declare variable of type // int, const int, const int*, // int * const and const int& typedef remove_const<int>::type A; typedef remove_const<const int>::type B; typedef remove_const<const int*>::type C; typedef remove_const<int* const>::type D; typedef remove_const<const int&>::type E; cout << std::boolalpha; // Checking const of the above // declared variables cout << "A is without const int? " << is_same<int, A>::value << endl; cout << "B is without const int? " << is_same<int, B>::value << endl; cout << "C is without const int? " << is_same<int, C>::value << endl; cout << "D is without const int? " << is_same<int, D>::value << endl; cout << "E is without const int? " << is_same<const int, E>::value << endl; return 0; } |
A is without const int? true B is without const int? true C is without const int? false D is without const int? false E is without const int? false
Reference: http://www.cplusplus.com/reference/type_traits/remove_const/
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Pi(π) in C++ with Examples
- cin get() in C++ with Examples
- std::less in C++ with Examples
- std::equal_to in C++ with Examples
- Manipulators in C++ with Examples
- std::add_cv in C++ with Examples
- SDL library in C/C++ with examples
- std::has_virtual_destructor in C++ with Examples
- basic_istream::get() in C++ with Examples
- std::is_nothrow_copy_constructible in C++ with Examples
- std::greater_equal in C++ with Examples
- ratio_equal() in C++ with examples
- std::make_signed in C++ with Examples
- std::is_trivially_move_constructible in C++ with Examples
- std::is_nothrow_constructible in C++ with Examples
- std::less_equal in C++ with Examples
- std::not_equal_to in C++ with Examples
- std::add_lvalue_reference in C++ with Examples
- std::is_trivially_move_assignable in C++ with Examples
- std::rank in C++ with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

