xref: /minix3/external/bsd/libc++/dist/libcxx/test/utilities/function.objects/arithmetic.operations/plus.pass.cpp (revision 4684ddb6aab0b36791c8099bc705d6140b3d05d0)
1*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
2*4684ddb6SLionel Sambuc //
3*4684ddb6SLionel Sambuc //                     The LLVM Compiler Infrastructure
4*4684ddb6SLionel Sambuc //
5*4684ddb6SLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open
6*4684ddb6SLionel Sambuc // Source Licenses. See LICENSE.TXT for details.
7*4684ddb6SLionel Sambuc //
8*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
9*4684ddb6SLionel Sambuc 
10*4684ddb6SLionel Sambuc // <functional>
11*4684ddb6SLionel Sambuc 
12*4684ddb6SLionel Sambuc // plus
13*4684ddb6SLionel Sambuc 
14*4684ddb6SLionel Sambuc #include <functional>
15*4684ddb6SLionel Sambuc #include <type_traits>
16*4684ddb6SLionel Sambuc #include <cassert>
17*4684ddb6SLionel Sambuc 
main()18*4684ddb6SLionel Sambuc int main()
19*4684ddb6SLionel Sambuc {
20*4684ddb6SLionel Sambuc     typedef std::plus<int> F;
21*4684ddb6SLionel Sambuc     const F f = F();
22*4684ddb6SLionel Sambuc     static_assert((std::is_base_of<std::binary_function<int, int, int>, F>::value), "");
23*4684ddb6SLionel Sambuc     assert(f(3, 2) == 5);
24*4684ddb6SLionel Sambuc #if _LIBCPP_STD_VER > 11
25*4684ddb6SLionel Sambuc     typedef std::plus<> F2;
26*4684ddb6SLionel Sambuc     const F2 f2 = F2();
27*4684ddb6SLionel Sambuc     assert(f2(3,2) == 5);
28*4684ddb6SLionel Sambuc     assert(f2(3.0, 2) == 5);
29*4684ddb6SLionel Sambuc     assert(f2(3, 2.5) == 5.5);
30*4684ddb6SLionel Sambuc 
31*4684ddb6SLionel Sambuc     constexpr int foo = std::plus<int> () (3, 2);
32*4684ddb6SLionel Sambuc     static_assert ( foo == 5, "" );
33*4684ddb6SLionel Sambuc 
34*4684ddb6SLionel Sambuc     constexpr int bar = std::plus<> () (3.0, 2);
35*4684ddb6SLionel Sambuc     static_assert ( bar == 5, "" );
36*4684ddb6SLionel Sambuc #endif
37*4684ddb6SLionel Sambuc }
38