C ++ 0x: conditional operator, xvalues ​​and decltype

I am retelling comp.std.C ++ Usenet discussion here because this group has become very unreliable. The last few messages that I sent there fell into the void, and the activity almost stopped. I doubt that I was banned, and / or everyone else just lost interest. We hope that all interested people will find this discussion, and there will be general migration. Maybe then they will appoint a new moderator.


Hello!

With my current interpretation of the N3126 wrt project of the conditional operator and x values, I expect the following statements to be true:

 int i = 0;
 int& j = true? i : i;
 int&& k = true? std::move(i) : std::move(i);   // #2
 assert(&i == &j); // Holds since C++98
 assert(&i == &k); // Should this hold as well?

5.16 / 4 says:

If the second and third operands [to the conditional operator] glvalues ​​of the same category of values ​​and have the same type, the result of this type and value [...]

, , glvalue , glvalue, , prvalue? GCC 4.5.1 ++ 0x . k . - , comiler , - x ?

, GCC / x.

: ? decltype.

 bool xvalue = std::is_rvalue_reference<
   decltype( true ? std::move(i) : std::move(i) ) >::value;

? GCC 4.5.1, xvalue . ?

,

+3
1

, GCC 4.5.1 §5.16/4. ?

, , . decltype §7.1.6.2/4:

, decltype (e), :

  • e - id- (5.2.5), decltype (e) - , e. , e , ;
  • , e (5.2.2) ( e ), decltype (e) ;
  • , e lvalue, decltype (e) T &, T - of e;
  • , decltype (e) - e. decltype - ( 5).

decltype , . . ,

  • , e x, decltype (e) T&&, T e

, , , , xvalues ​​ prvalues. , std::common_type (§20.7.6.6/3).

( : vP):

template< typename T1, typename T2 >
struct common_type_and_category {
    typedef typename std::conditional<
        std::is_same< T1, T2 >::value,
        T1,
        typename std::common_type< T1, T2 >::type
    >::type type;
};
+2

Source: https://habr.com/ru/post/1769040/


All Articles