blob: 198894023cd795f6bde9f657e4734f8da860a704 [file] [log] [blame]
Howard Hinnantc52f43e2010-08-22 00:59:46 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc52f43e2010-08-22 00:59:46 +00007//
8//===----------------------------------------------------------------------===//
9
10// <functional>
11
12// negate
13
14#include <functional>
15#include <type_traits>
16#include <cassert>
17
Stephan T. Lavaveje6198622016-11-04 20:26:59 +000018#include "test_macros.h"
19
Howard Hinnantc52f43e2010-08-22 00:59:46 +000020int main()
21{
22 typedef std::negate<int> F;
23 const F f = F();
Marshall Clow87d03942015-01-07 21:51:30 +000024 static_assert((std::is_same<F::argument_type, int>::value), "" );
25 static_assert((std::is_same<F::result_type, int>::value), "" );
Howard Hinnantc52f43e2010-08-22 00:59:46 +000026 assert(f(36) == -36);
Stephan T. Lavaveje6198622016-11-04 20:26:59 +000027#if TEST_STD_VER > 11
Marshall Clowff464092013-07-29 14:21:53 +000028 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 Clow9738caf2013-09-28 19:06:12 +000033
34 constexpr int foo = std::negate<int> () (3);
35 static_assert ( foo == -3, "" );
36
Stephan T. Lavavej637a6f62016-12-08 21:38:01 +000037 constexpr double bar = std::negate<> () (3.0);
38 static_assert ( bar == -3.0, "" );
Marshall Clowff464092013-07-29 14:21:53 +000039#endif
Howard Hinnantc52f43e2010-08-22 00:59:46 +000040}