71 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS10 11// <functional>12 13// bit_xor14 15#include <functional>16#include <type_traits>17#include <cassert>18 19#include "test_macros.h"20 21int main(int, char**)22{23 {24 typedef std::bit_xor<int> F;25 const F f = F();26#if TEST_STD_VER <= 1727 static_assert((std::is_same<int, F::first_argument_type>::value), "" );28 static_assert((std::is_same<int, F::second_argument_type>::value), "" );29 static_assert((std::is_same<int, F::result_type>::value), "" );30#endif31 assert(f(0xEA95, 0xEA95) == 0);32 assert(f(0xEA95, 0x58D3) == 0xB246);33 assert(f(0x58D3, 0xEA95) == 0xB246);34 assert(f(0x58D3, 0) == 0x58D3);35 assert(f(0xFFFF, 0x58D3) == 0xA72C);36 }37#if TEST_STD_VER > 1138 {39 typedef std::bit_xor<> F2;40 const F2 f = F2();41 assert(f(0xEA95, 0xEA95) == 0);42 assert(f(0xEA95L, 0xEA95) == 0);43 assert(f(0xEA95, 0xEA95L) == 0);44 45 assert(f(0xEA95, 0x58D3) == 0xB246);46 assert(f(0xEA95L, 0x58D3) == 0xB246);47 assert(f(0xEA95, 0x58D3L) == 0xB246);48 49 assert(f(0x58D3, 0xEA95) == 0xB246);50 assert(f(0x58D3L, 0xEA95) == 0xB246);51 assert(f(0x58D3, 0xEA95L) == 0xB246);52 53 assert(f(0x58D3, 0) == 0x58D3);54 assert(f(0x58D3L, 0) == 0x58D3);55 assert(f(0x58D3, 0L) == 0x58D3);56 57 assert(f(0xFFFF, 0x58D3) == 0xA72C);58 assert(f(0xFFFFL, 0x58D3) == 0xA72C);59 assert(f(0xFFFF, 0x58D3L) == 0xA72C);60 61 constexpr int foo = std::bit_xor<int> () (0x58D3, 0xEA95);62 static_assert ( foo == 0xB246, "" );63 64 constexpr int bar = std::bit_xor<> () (0x58D3L, 0xEA95);65 static_assert ( bar == 0xB246, "" );66 }67#endif68 69 return 0;70}71