<type_traits>頭文件中提供了C++ STL的std::is_literal_type模板。 C++ STL的std::is_literal_type模板用於檢查T是否為文字類型。如果T是文字類型,則返回布爾值true,否則返回false。
頭文件:
#include<type_traits>
模板:
template< class T > struct is_literal_type;
用法:
std::is_literal_type::value
參數:模板std::is_literal_type接受單個參數T(Trait類),以檢查T是否為文字類型。
返回值:模板std::is_literal_type返回一個布爾變量,如下所示:
- True:如果類型T是文字類型。
- False:如果類型T不是文字類型。
以下是在C /C++中演示std::is_literal_type:的程序:
程序:
// C++ program to illustrate
// std::is_literal_type
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
// Declare Classes
class X {
};
class Y {
// Destructor
~Y() {}
};
// Declare structures
struct A {
int m;
};
struct B {
virtual ~B();
};
// Driver Code
int main()
{
cout << boolalpha;
// Check if int is literal type?
cout << "int:"
<< is_literal_type<int>::value
<< endl;
// Check if class X is literal type?
cout << "class X:"
<< is_literal_type<X>::value
<< endl;
// Check if class Y is literal type?
cout << "class Y:"
<< is_literal_type<Y>::value
<< endl;
// Check if int* is literal type?
cout << "int*:"
<< is_literal_type<int*>::value
<< endl;
// Check if struct A is literal type?
cout << "struct A:"
<< is_literal_type<A>::value
<< endl;
// Check if struct B is literal type?
cout << "struct B:"
<< is_literal_type<B>::value
<< endl;
return 0;
}
輸出:
int:true class X:true class Y:false int*:true struct A:true struct B:false
參考: http://www.cplusplus.com/reference/type_traits/is_literal_type/
相關用法
- C語言 strtok()、strtok_r()用法及代碼示例
- C語言 memset()用法及代碼示例
- C++ std::mismatch()用法及代碼示例
- C++ wcscpy()用法及代碼示例
- C++ wcscmp()用法及代碼示例
- C++ set_symmetric_difference用法及代碼示例
- C++ ratio_equal()用法及代碼示例
- C++ std::equal_to用法及代碼示例
- C++ quick_exit()用法及代碼示例
- C++ multiset lower_bound()用法及代碼示例
- C++ multiset upper_bound()用法及代碼示例
- C++ multiset max_size()用法及代碼示例
- C++ forward_list max_size()用法及代碼示例
- C++ std::allocator()用法及代碼示例
- C++ array data()用法及代碼示例
- C++ multiset size()用法及代碼示例
- C++ ratio_not_equal()用法及代碼示例
注:本文由純淨天空篩選整理自bansal_rtk_大神的英文原創作品 std::is_literal_type in C++ with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。