<type_traits>

類模板
<type_traits>

std::remove_const

template <class T> struct remove_const;
移除const限定符
獲取型別T不帶頂層const的頂層限定符。

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

如果已知Tconst限定的,這與...是相同的型別T但是移除了它的const限定符。否則,它就是T不變。

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

模板引數

T
一個型別。

成員型別

成員型別定義
型別如果已知Tconst限定的,與...是相同的型別T但移除了const限定符。
否則,T

示例

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

int main() {
  typedef const char cc;
  std::remove_const<cc>::type a;             // char a
  std::remove_const<const char*>::type b;    // const char* b
  std::remove_const<char* const>::type c;    // char* c

  a = 'x';
  b = "remove_const";
  c = new char[10];

  std::cout << b << std::endl;

  return 0;
}

輸出
remove_const


另見