<type_traits>頭文件中提供了C++ STL的std::remove_volatile模板。 C++ STL的std::remove_volatile模板用於獲取T,而不使用volatile限定。如果T不具有volatile限定,則它返回布爾值true,否則返回false。以下是相同的語法:
頭文件:
#include<type_traits>
模板類別:
template <class <T> struct remove_volatile;
用法:
std::remove_volatile::value
參數:模板std::rmeove_volatile接受單個參數T(Trait類),以檢查T是否不具有volatile限定。
返回值:模板std::remove_volatile返回一個布爾值:
- True:如果類型T沒有揮發合格。
- False:如果類型T具有揮發性認證。
下麵是在C++中演示std::remove_volatile的程序:
程序1:
// C++ program to illustrate
// std::remove_volatile
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
// Driver Code
int main()
{
// Declare variable of type
// volatile (int, const int, const int*,
// int * const and const int&)
typedef remove_volatile<int>::type A;
typedef remove_volatile<volatile int>::type B;
typedef remove_volatile<int* volatile>::type C;
typedef remove_volatile<volatile int*>::type D;
typedef remove_volatile<volatile int&>::type E;
cout << boolalpha;
// Checking the non-volatileness
// of the above declared variable
cout << "checking Non-volatileness:"
<< endl;
cout << "A:"
<< is_volatile<A>::value
<< endl;
cout << "B:"
<< is_volatile<B>::value
<< endl;
cout << "C:"
<< is_volatile<C>::value
<< endl;
cout << "D:"
<< is_volatile<D>::value
<< endl;
cout << "E:"
<< is_volatile<E>::value
<< endl;
return 0;
}
輸出:
checking Non-volatileness: A:false B:false C:false D:false E:false
程序2:
// C++ program to illustrate
// std::remove_volatile
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
// Driver Code
int main()
{
// Declare variable of type
// volatile (int, const int, const int*,
// int * const and const int&)
typedef add_volatile<int>::type A;
typedef add_volatile<volatile int>::type B;
typedef remove_cv<float>::type a;
typedef remove_cv<char* const>::type b;
typedef remove_cv<const char*>::type c;
cout << boolalpha;
// Checking the non-volatileness
// of the above declared variable
cout << "checking Non-volatileness:"
<< endl;
cout << "A:"
<< is_volatile<A>::value
<< endl;
cout << "B:"
<< is_volatile<B>::value
<< endl;
cout << "C:"
<< is_volatile<a>::value
<< endl;
cout << "D:"
<< is_volatile<b>::value
<< endl;
cout << "E:"
<< is_volatile<c>::value
<< endl;
return 0;
}
輸出:
checking Non-volatileness: A:true B:true C:false D:false E:false
參考: http://www.cplusplus.com/reference/type_traits/remove_volatile/
相關用法
- 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::remove_volatile in C++ with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。