<type_traits>

類模板
<type_traits>

std::is_assignable

template <class T, class U> struct is_assignable;
是否可賦值

用於識別U是一個型別,可以賦值T.

該類繼承自 integral_constant,根據T支援賦值U.


模板引數

T, U
完整型別,或void(可能帶 cv 限定),或者一個未知邊界的陣列。

成員型別

繼承自 integral_constant
成員型別定義
value_typebool
型別true_type 或 false_type

成員常量

繼承自 integral_constant
成員常量定義
truefalse

成員函式

繼承自 integral_constant

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// is_assignable example
#include <iostream>
#include <type_traits>

struct A { };
struct B { B& operator= (const A&){return *this;} };

int main() {
  std::cout << std::boolalpha;
  std::cout << "is_assignable:" << std::endl;
  std::cout << "A=B: " << std::is_assignable<A,B>::value << std::endl;
  std::cout << "B=A: " << std::is_assignable<B,A>::value << std::endl;
  return 0;
}

輸出
is_assignable:
A=B: false
B=A: true


另見