
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
is_const Template in C++
In this article we will be discussing the working, syntax and examples of std::is_const template in C++ STL.
is_const template in C++ is used to check whether the defined type is a const-qualified type or not.
What is const-qualified type?
We say a type as a const-qualified when the value of the type is constant. Constant data type is a type in which once a value is initialised in a const can’t be changed or altered throughout the program.
Syntax
template <class T> is_const;
Parameters
The template can have only parameter of type T, and check whether the given type is a constqualifier or not
Return value
It returns a Boolean value, true if the given type is a const-qualifier, and false if the given type is not a const-qualifier.
Example
Input: is_const<const int>::value; Output: True Input: is_const<int>::value; Output: False
Example
#include <iostream> #include <type_traits> using namespace std; int main() { cout << boolalpha; cout << "checking for is_const template: "; cout << "\nInt : "<<is_const<int>::value; cout << "\nConst int : "<< is_const<const int>::value; cout << "\nConst int& : "<< is_const<const int&>::value; return 0; }
Output
If we run the above code it will generate the following output −
checking for is_const template: Int : false Const int : true Const int& : false
Example
#include <iostream> #include <type_traits> using namespace std; int main() { cout << boolalpha; cout << "checking for is_const template: "; cout << "\nFloat : "<<is_const<float>::value; cout << "\nChar : "<<is_const<char>::value; cout << "\nFloat *: "<<is_const<float*>::value; cout << "\nChar *: "<<is_const<char*>::value; cout << "\nConst int* : "<< is_const<const int*>::value; cout << "\nint* const : "<< is_const<int* const>::value; return 0; }
Output
If we run the above code it will generate the following output −
checking for is_const template: Float : false Char: false Float *: false Char *: fakse Const int* : false int* const: true
- Related Articles
- What is the difference between const int*, const int * const, and int const *?
- Difference between const int*, const int * const, and int const * in C
- Difference between const int*, const int * const, and int const * in C/C++?
- Difference between const char* p, char * const p, and const char * const p in C
- What is the const Keyword in C++?
- JavaScript Const
- Const Qualifier in C
- Const cast in C++
- Template Metaprogramming in C++
- is_final template in C++
- is_fundamental Template in C++
- is_pod template in C++
- is_pointer Template in C++
- is_signed template in C++
- is_unsigned template in C++
- is_void template in C++
