Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <functional> |
| 11 | |
| 12 | // negate |
| 13 | |
| 14 | #include <functional> |
| 15 | #include <type_traits> |
| 16 | #include <cassert> |
| 17 | |
Stephan T. Lavavej | e619862 | 2016-11-04 20:26:59 +0000 | [diff] [blame] | 18 | #include "test_macros.h" |
| 19 | |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 20 | int main() |
| 21 | { |
| 22 | typedef std::negate<int> F; |
| 23 | const F f = F(); |
Marshall Clow | 87d0394 | 2015-01-07 21:51:30 +0000 | [diff] [blame] | 24 | static_assert((std::is_same<F::argument_type, int>::value), "" ); |
| 25 | static_assert((std::is_same<F::result_type, int>::value), "" ); |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 26 | assert(f(36) == -36); |
Stephan T. Lavavej | e619862 | 2016-11-04 20:26:59 +0000 | [diff] [blame] | 27 | #if TEST_STD_VER > 11 |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 28 | typedef std::negate<> F2; |
| 29 | const F2 f2 = F2(); |
| 30 | assert(f2(36) == -36); |
| 31 | assert(f2(36L) == -36); |
| 32 | assert(f2(36.0) == -36); |
Marshall Clow | 9738caf | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 33 | |
| 34 | constexpr int foo = std::negate<int> () (3); |
| 35 | static_assert ( foo == -3, "" ); |
| 36 | |
Stephan T. Lavavej | 637a6f6 | 2016-12-08 21:38:01 +0000 | [diff] [blame] | 37 | constexpr double bar = std::negate<> () (3.0); |
| 38 | static_assert ( bar == -3.0, "" ); |
Marshall Clow | ff46409 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 39 | #endif |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 40 | } |