Kelas is_const
Menguji apakah jenis adalah const.
Sintaks
template <class Ty>
struct is_const;
Parameter
Ty
Jenis yang akan dikueri.
Keterangan
Instans predikat jenis memegang true jika Ty adalah const-qualified
.
Contoh
// std__type_traits__is_const.cpp
// compile with: /EHsc
#include <type_traits>
#include <iostream>
struct trivial
{
int val;
};
int main()
{
std::cout << "is_const<trivial> == " << std::boolalpha
<< std::is_const<trivial>::value << std::endl;
std::cout << "is_const<const trivial> == " << std::boolalpha
<< std::is_const<const trivial>::value << std::endl;
std::cout << "is_const<int> == " << std::boolalpha
<< std::is_const<int>::value << std::endl;
std::cout << "is_const<const int> == " << std::boolalpha
<< std::is_const<const int>::value << std::endl;
return (0);
}
is_const<trivial> == false
is_const<const trivial> == true
is_const<int> == false
is_const<const int> == true
Persyaratan
Header:<type_traits>
Namespace: std