- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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