What you are looking for std::is_const. If the type you specify is const, valuewill be true. If not, there valuewill be false.
Here is an example you can find on this page:
#include <iostream>
#include <type_traits> //needed for is_const
int main()
{
std::cout << boolalpha;
std::cout << std::is_const<int>::value << '\n';
std::cout << std::is_const<const int>::value << '\n';
}
Conclusion:
false
true
Since you were trying to make your own, I would recommend that you familiarize yourself with a possible implementation that is provided to understand how this works if you need to do this in the future. This is a good learning experience.
source
share