blob: 4e27ff61bd5eb490cd9ce48f1b196bce4ac5d462 [file] [log] [blame]
 // DR 339 // // Test of the use of various assignment operators with SFINAE // Boilerplate helpers typedef char yes_type; struct no_type { char data[2]; }; template T create_a(); template struct type { }; template struct enable_if { typedef T type; }; template struct enable_if { }; #define JOIN( X, Y ) DO_JOIN( X, Y ) #define DO_JOIN( X, Y ) DO_JOIN2(X,Y) #define DO_JOIN2( X, Y ) X##Y #define DEFINE_INFIX_BINARY_TRAIT(Name,Op) \ template \ typename enable_if<(sizeof(create_a() Op create_a(), 1) > 0), \ yes_type>::type \ JOIN(check_,Name)(type, type); \ \ no_type JOIN(check_,Name)(...); \ \ template \ struct Name \ { \ static const bool value = \ (sizeof(JOIN(check_,Name)(type(), type())) == sizeof(yes_type)); \ } #ifdef __GXX_EXPERIMENTAL_CXX0X__ # define STATIC_ASSERT(Expr) static_assert(Expr, #Expr) #else # define STATIC_ASSERT(Expr) int JOIN(a,__LINE__)[Expr? 1 : -1] #endif struct Y { Y& operator=(Y&); }; struct X { X& operator=(Y); X& operator+=(X); X& operator-=(X); X& operator*=(X); X& operator/=(X); X& operator%=(X); X& operator^=(X); X& operator&=(X); X& operator|=(X); X& operator<<=(X); X& operator>>=(X); }; struct Z { }; // is_assignable DEFINE_INFIX_BINARY_TRAIT(is_assignable, =); STATIC_ASSERT((is_assignable::value)); STATIC_ASSERT((is_assignable::value)); STATIC_ASSERT((is_assignable::value)); STATIC_ASSERT((!is_assignable::value)); STATIC_ASSERT((is_assignable::value)); STATIC_ASSERT((is_assignable::value)); STATIC_ASSERT((!is_assignable::value)); STATIC_ASSERT((!is_assignable::value)); STATIC_ASSERT((!is_assignable::value)); // has_plus_assign DEFINE_INFIX_BINARY_TRAIT(has_plus_assign, +=); X& operator+=(X&, Y); STATIC_ASSERT((has_plus_assign::value)); STATIC_ASSERT((has_plus_assign::value)); STATIC_ASSERT((has_plus_assign::value)); STATIC_ASSERT((has_plus_assign::value)); STATIC_ASSERT((!has_plus_assign::value)); STATIC_ASSERT((has_plus_assign::value)); STATIC_ASSERT((!has_plus_assign::value)); STATIC_ASSERT((!has_plus_assign::value)); STATIC_ASSERT((!has_plus_assign::value)); // has_minus_assign DEFINE_INFIX_BINARY_TRAIT(has_minus_assign, -=); X& operator-=(X&, Y); STATIC_ASSERT((has_minus_assign::value)); STATIC_ASSERT((has_minus_assign::value)); STATIC_ASSERT((has_minus_assign::value)); STATIC_ASSERT((has_minus_assign::value)); STATIC_ASSERT((!has_minus_assign::value)); STATIC_ASSERT((has_minus_assign::value)); STATIC_ASSERT((!has_minus_assign::value)); STATIC_ASSERT((!has_minus_assign::value)); STATIC_ASSERT((!has_minus_assign::value)); STATIC_ASSERT((!has_minus_assign::value)); // has_multiply_assign DEFINE_INFIX_BINARY_TRAIT(has_multiply_assign, *=); X& operator*=(X&, Y); STATIC_ASSERT((has_multiply_assign::value)); STATIC_ASSERT((has_multiply_assign::value)); STATIC_ASSERT((has_multiply_assign::value)); STATIC_ASSERT((!has_multiply_assign::value)); STATIC_ASSERT((!has_multiply_assign::value)); STATIC_ASSERT((has_multiply_assign::value)); STATIC_ASSERT((!has_multiply_assign::value)); STATIC_ASSERT((!has_multiply_assign::value)); STATIC_ASSERT((!has_multiply_assign::value)); STATIC_ASSERT((!has_multiply_assign::value)); // has_divide_assign DEFINE_INFIX_BINARY_TRAIT(has_divide_assign, /=); X& operator/=(X&, Y); STATIC_ASSERT((has_divide_assign::value)); STATIC_ASSERT((has_divide_assign::value)); STATIC_ASSERT((has_divide_assign::value)); STATIC_ASSERT((!has_divide_assign::value)); STATIC_ASSERT((!has_divide_assign::value)); STATIC_ASSERT((has_divide_assign::value)); STATIC_ASSERT((!has_divide_assign::value)); STATIC_ASSERT((!has_divide_assign::value)); STATIC_ASSERT((!has_divide_assign::value)); // has_remainder_assign DEFINE_INFIX_BINARY_TRAIT(has_remainder_assign, %=); X& operator%=(X&, Y); STATIC_ASSERT((has_remainder_assign::value)); STATIC_ASSERT((has_remainder_assign::value)); STATIC_ASSERT((!has_remainder_assign::value)); STATIC_ASSERT((has_remainder_assign::value)); STATIC_ASSERT((!has_remainder_assign::value)); STATIC_ASSERT((!has_remainder_assign::value)); STATIC_ASSERT((has_remainder_assign::value)); STATIC_ASSERT((!has_remainder_assign::value)); STATIC_ASSERT((!has_remainder_assign::value)); STATIC_ASSERT((!has_remainder_assign::value)); // has_xor_assign DEFINE_INFIX_BINARY_TRAIT(has_xor_assign, ^=); X& operator^=(X&, Y); STATIC_ASSERT((has_xor_assign::value)); STATIC_ASSERT((has_xor_assign::value)); STATIC_ASSERT((!has_xor_assign::value)); STATIC_ASSERT((has_xor_assign::value)); STATIC_ASSERT((!has_xor_assign::value)); STATIC_ASSERT((!has_xor_assign::value)); STATIC_ASSERT((has_xor_assign::value)); STATIC_ASSERT((!has_xor_assign::value)); STATIC_ASSERT((!has_xor_assign::value)); STATIC_ASSERT((!has_xor_assign::value)); // has_bitand_assign DEFINE_INFIX_BINARY_TRAIT(has_bitand_assign, &=); X& operator&=(X&, Y); STATIC_ASSERT((has_bitand_assign::value)); STATIC_ASSERT((has_bitand_assign::value)); STATIC_ASSERT((!has_bitand_assign::value)); STATIC_ASSERT((has_bitand_assign::value)); STATIC_ASSERT((!has_bitand_assign::value)); STATIC_ASSERT((!has_bitand_assign::value)); STATIC_ASSERT((has_bitand_assign::value)); STATIC_ASSERT((!has_bitand_assign::value)); STATIC_ASSERT((!has_bitand_assign::value)); STATIC_ASSERT((!has_bitand_assign::value)); // has_bitor_assign DEFINE_INFIX_BINARY_TRAIT(has_bitor_assign, |=); X& operator|=(X&, Y); STATIC_ASSERT((has_bitor_assign::value)); STATIC_ASSERT((has_bitor_assign::value)); STATIC_ASSERT((!has_bitor_assign::value)); STATIC_ASSERT((has_bitor_assign::value)); STATIC_ASSERT((!has_bitor_assign::value)); STATIC_ASSERT((!has_bitor_assign::value)); STATIC_ASSERT((has_bitor_assign::value)); STATIC_ASSERT((!has_bitor_assign::value)); STATIC_ASSERT((!has_bitor_assign::value)); STATIC_ASSERT((!has_bitor_assign::value)); // has_left_shift_assign DEFINE_INFIX_BINARY_TRAIT(has_left_shift_assign, <<=); X& operator<<=(X&, Y); STATIC_ASSERT((has_left_shift_assign::value)); STATIC_ASSERT((has_left_shift_assign::value)); STATIC_ASSERT((!has_left_shift_assign::value)); STATIC_ASSERT((has_left_shift_assign::value)); STATIC_ASSERT((!has_left_shift_assign::value)); STATIC_ASSERT((!has_left_shift_assign::value)); STATIC_ASSERT((has_left_shift_assign::value)); STATIC_ASSERT((!has_left_shift_assign::value)); STATIC_ASSERT((!has_left_shift_assign::value)); STATIC_ASSERT((!has_left_shift_assign::value)); // has_right_shift_assign DEFINE_INFIX_BINARY_TRAIT(has_right_shift_assign, >>=); X& operator>>=(X&, Y); STATIC_ASSERT((has_right_shift_assign::value)); STATIC_ASSERT((has_right_shift_assign::value)); STATIC_ASSERT((!has_right_shift_assign::value)); STATIC_ASSERT((has_right_shift_assign::value)); STATIC_ASSERT((!has_right_shift_assign::value)); STATIC_ASSERT((!has_right_shift_assign::value)); STATIC_ASSERT((has_right_shift_assign::value)); STATIC_ASSERT((!has_right_shift_assign::value)); STATIC_ASSERT((!has_right_shift_assign::value)); STATIC_ASSERT((!has_right_shift_assign::value));