blob: a09e59c784c793219fbe2edcf2c358c3ef4b8231 [file] [log] [blame]
Howard Hinnant94b2dd02010-08-22 00:59:46 +00001//===----------------------------------------------------------------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// 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 Hinnant94b2dd02010-08-22 00:59:46 +00006//
7//===----------------------------------------------------------------------===//
8
9// <functional>
10
11// multiplies
12
13#include <functional>
14#include <type_traits>
15#include <cassert>
16
Stephan T. Lavavej0f901c72016-11-04 20:26:59 +000017#include "test_macros.h"
18
JF Bastien2df59c52019-02-04 20:31:13 +000019int main(int, char**)
Howard Hinnant94b2dd02010-08-22 00:59:46 +000020{
21 typedef std::multiplies<int> F;
22 const F f = F();
Marshall Clow66369c02015-01-07 20:31:06 +000023 static_assert((std::is_same<int, F::first_argument_type>::value), "" );
24 static_assert((std::is_same<int, F::second_argument_type>::value), "" );
25 static_assert((std::is_same<int, F::result_type>::value), "" );
Howard Hinnant94b2dd02010-08-22 00:59:46 +000026 assert(f(3, 2) == 6);
Stephan T. Lavavej0f901c72016-11-04 20:26:59 +000027#if TEST_STD_VER > 11
Marshall Clow83c08b42013-07-29 14:21:53 +000028 typedef std::multiplies<> F2;
29 const F2 f2 = F2();
30 assert(f2(3,2) == 6);
31 assert(f2(3.0, 2) == 6);
32 assert(f2(3, 2.5) == 7.5); // exact in binary
Marshall Clow3d5134dd2013-09-28 19:06:12 +000033
34 constexpr int foo = std::multiplies<int> () (3, 2);
35 static_assert ( foo == 6, "" );
36
Stephan T. Lavavejc255fa52016-12-08 21:38:01 +000037 constexpr double bar = std::multiplies<> () (3.0, 2);
38 static_assert ( bar == 6.0, "" );
Marshall Clow83c08b42013-07-29 14:21:53 +000039#endif
JF Bastien2df59c52019-02-04 20:31:13 +000040
41 return 0;
Howard Hinnant94b2dd02010-08-22 00:59:46 +000042}