<type_traits>頭文件中提供了C++ STL的std::remove_cv模板。 C++ STL的std::remove_cv模板用於獲取類型T,而沒有const和volatile限定。如果T不帶const和volatile限定,則返回布爾值true,否則返回false。
頭文件:
#include<type_traits>
模板:
template<class T> struct remove_cv;
用法:
std::remove_cv<T>::type a;
參數:模板std::remove_cv接受單個參數T(Trait類),以檢查T是否沒有const和volatile限定。
返回值:
以下是在C++中演示std::remove_cv的程序:
程序:
// C++ program to illustrate std::remove_cv
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
// Driver Code
int main()
{
// Declare variable of type int, const
// int, volatile int and const volatile int
typedef remove_cv<int>::type A;
typedef remove_cv<const int>::type B;
typedef remove_cv<volatile int>::type C;
typedef remove_cv<const volatile int&>::type D;
cout << boolalpha;
cout << "A:"
<< is_same<const volatile int, A>::value
<< endl;
cout << "B:"
<< is_same<const volatile int, B>::value
<< endl;
cout << "C:"
<< is_same<int, C>::value
<< endl;
cout << "D:"
<< is_same<int, D>::value
<< endl;
return 0;
}
輸出:
A:false B:false C:true D:false
參考: http://www.cplusplus.com/reference/type_traits/remove_cv/
相關用法
- C/C++ fseek()用法及代碼示例
- C++ std::search_n用法及代碼示例
- C++ tellg()用法及代碼示例
- C++ wcstok()用法及代碼示例
- C++ wcsstr()用法及代碼示例
- C++ wcsncpy()用法及代碼示例
- C++ forward_list::cend()用法及代碼示例
- C++ Private和Protected的區別用法及代碼示例
- C++ std::is_destructible用法及代碼示例
- C++ std::is_nothrow_move_constructible用法及代碼示例
- C++ std::is_trivially_default_constructible用法及代碼示例
- C++ std::numeric_limits::digits用法及代碼示例
- C++ std::underlying_type用法及代碼示例
注:本文由純淨天空篩選整理自bansal_rtk_大神的英文原創作品 std::remove_cv in C++ with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。