<type_traits>

類模板
<type_traits>

std::remove_volatile

template <class T> struct remove_volatile;
移除 volatile 頂層限定符
獲取型別T型別volatile的頂層限定符。

轉換後的類型別名為成員型別remove_volatile::type.

如果已知Tvolatile限定的,則與T相同,但移除了其volatile限定。否則,它就是T不變。

請注意,此類僅使用另一個型別作為模型來獲取一個型別,但它不在這兩個型別之間轉換值或物件。要顯式移除物件的 volatile 限定符,const_cast可以使用。

模板引數

T
一個型別。

成員型別

成員型別定義
型別如果已知Tvolatile限定的,則與T相同,但移除了 volatile 限定。
否則,T

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// remove_volatile example
#include <iostream>
#include <type_traits>

int main() {
  typedef volatile int vint;
  std::remove_volatile<vint>::type a;                    // int a
  std::remove_volatile<const volatile int>::type b = 0;  // const int b
  std::remove_volatile<volatile int*>::type c;           // volatile int* c
  std::remove_volatile<int* volatile>::type d;           // int* d

  if (std::is_volatile<decltype(d)>::value)
    std::cout << "type of d is volatile" << std::endl;
  else
    std::cout << "type of d is not volatile" << std::endl;

  return 0;
}

輸出
type of d is not volatile


另見