Howard Hinnant | 94b2dd0 | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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-exception |
Howard Hinnant | 94b2dd0 | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <functional> |
| 10 | |
| 11 | // negate |
| 12 | |
| 13 | #include <functional> |
| 14 | #include <type_traits> |
| 15 | #include <cassert> |
| 16 | |
Stephan T. Lavavej | 0f901c7 | 2016-11-04 20:26:59 +0000 | [diff] [blame] | 17 | #include "test_macros.h" |
| 18 | |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 19 | int main(int, char**) |
Howard Hinnant | 94b2dd0 | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 20 | { |
| 21 | typedef std::negate<int> F; |
| 22 | const F f = F(); |
Marshall Clow | 601fa8d | 2015-01-07 21:51:30 +0000 | [diff] [blame] | 23 | static_assert((std::is_same<F::argument_type, int>::value), "" ); |
| 24 | static_assert((std::is_same<F::result_type, int>::value), "" ); |
Howard Hinnant | 94b2dd0 | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 25 | assert(f(36) == -36); |
Stephan T. Lavavej | 0f901c7 | 2016-11-04 20:26:59 +0000 | [diff] [blame] | 26 | #if TEST_STD_VER > 11 |
Marshall Clow | 83c08b4 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 27 | typedef std::negate<> F2; |
| 28 | const F2 f2 = F2(); |
| 29 | assert(f2(36) == -36); |
| 30 | assert(f2(36L) == -36); |
| 31 | assert(f2(36.0) == -36); |
Marshall Clow | 3d5134dd | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 32 | |
| 33 | constexpr int foo = std::negate<int> () (3); |
| 34 | static_assert ( foo == -3, "" ); |
| 35 | |
Stephan T. Lavavej | c255fa5 | 2016-12-08 21:38:01 +0000 | [diff] [blame] | 36 | constexpr double bar = std::negate<> () (3.0); |
| 37 | static_assert ( bar == -3.0, "" ); |
Marshall Clow | 83c08b4 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 38 | #endif |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 39 | |
| 40 | return 0; |
Howard Hinnant | 94b2dd0 | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 41 | } |