blob: 7419b70e0b8f67fdc520023e8afb551595969dad [file] [log] [blame]
Howard Hinnant94b2dd02010-08-22 00:59:46 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnant412dbeb2010-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 Hinnant94b2dd02010-08-22 00:59:46 +00007//
8//===----------------------------------------------------------------------===//
9
10// <functional>
11
12// divides
13
14#include <functional>
15#include <type_traits>
16#include <cassert>
17
Stephan T. Lavavej0f901c72016-11-04 20:26:59 +000018#include "test_macros.h"
19
Howard Hinnant94b2dd02010-08-22 00:59:46 +000020int main()
21{
22 typedef std::divides<int> F;
23 const F f = F();
Marshall Clow66369c02015-01-07 20:31:06 +000024 static_assert((std::is_same<int, F::first_argument_type>::value), "" );
25 static_assert((std::is_same<int, F::second_argument_type>::value), "" );
26 static_assert((std::is_same<int, F::result_type>::value), "" );
Howard Hinnant94b2dd02010-08-22 00:59:46 +000027 assert(f(36, 4) == 9);
Stephan T. Lavavej0f901c72016-11-04 20:26:59 +000028#if TEST_STD_VER > 11
Marshall Clow83c08b42013-07-29 14:21:53 +000029 typedef std::divides<> F2;
30 const F2 f2 = F2();
31 assert(f2(36, 4) == 9);
32 assert(f2(36.0, 4) == 9);
33 assert(f2(18, 4.0) == 4.5); // exact in binary
Marshall Clow3d5134dd2013-09-28 19:06:12 +000034
35 constexpr int foo = std::divides<int> () (3, 2);
36 static_assert ( foo == 1, "" );
37
Stephan T. Lavavejc255fa52016-12-08 21:38:01 +000038 constexpr double bar = std::divides<> () (3.0, 2);
39 static_assert ( bar == 1.5, "" ); // exact in binary
Marshall Clow83c08b42013-07-29 14:21:53 +000040#endif
Howard Hinnant94b2dd02010-08-22 00:59:46 +000041}