How to interpret declval <_Dest> () = declval <_Src> () in is_assignable

I am trying to understand how to interpret the declared <_Dest> () = declval <_Src> () in the implementation of is_assignable.

declval turns the type into a link. Given this, I translate the expression into one of the following four possibilities:

  • _Dest && = _Src &&
  • _Dest && = _Src &
  • _Dest & = _Src &&
  • _Dest & = _Src &

Then I created two helper functions.

template <typename T> T rvalue();
template <typename T> T& lvalue();

My understanding is that four expressions can be implemented using template functions.

  • _Dest && = _Src && -----> rvalue <_Dest> () = rvalue <_Src> ()

The same applies to the other three.

decltype (declval < _Dest > () = declval < _Src > (),..), .

  • _Dest = int, _src= int. # 3 # 4. is_assignable true # 3 # 4. .
  • _Dest = int, _src= double. ,
  • _Dest = double, _src= int. is_assignable . r. is_assignable true .

  • decl < _Dest > () = declval < _Src > ()? , . , ?
  • is_assignable _Dest = double, _src= int case?

.

+4
1

std::declval (++ 11 §20.2.4 [declval] p1):

template <class T>
typename add_rvalue_reference<T>::type declval() noexcept;

(§8.3.2 [dcl.ref] p6) , declval lvalue, T lvalue rvalue . , .

, double&& , . §5.17 [expr.ass] p1:

(=) . lvalue lvalue, .

[ ].

- lvalues ​​- , lvalue:

class foo {
  foo& operator = (const foo&) & = default;
  foo& operator = (foo&&) & = default;
};
+3

All Articles