class template
<type_traits>
std::remove_const
template <class T> struct remove_const;
Remove const qualification
Obtains the type T without top-level const qualification.
The transformed type is aliased as member type remove_const::type.
If T is const-qualified, this is the same type as T but with its const-qualification removed. Otherwise, it is T unchanged.
Notice that this class merely obtains a type using another type as model, but it does not transform values or objects between those types. To explicitly remove the const-qualifier of an object, const_cast can be used.
Template parameters
- T
- A type.
Member types
member type | definition |
type | If T is const-qualified, the same type as T but with the const-qualification removed.
Otherwise, T |
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
// remove_const example
#include <iostream>
#include <type_traits>
int main() {
typedef const char cc;
std::remove_const<cc>::type a; // char a
std::remove_const<const char*>::type b; // const char* b
std::remove_const<char* const>::type c; // char* c
a = 'x';
b = "remove_const";
c = new char[10];
std::cout << b << std::endl;
return 0;
}
| |
Output: