Howard Hinnant | 94b2dd0 | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | 412dbeb | 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 | 94b2dd0 | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <functional> |
| 11 | |
| 12 | // divides |
| 13 | |
| 14 | #include <functional> |
| 15 | #include <type_traits> |
| 16 | #include <cassert> |
| 17 | |
Stephan T. Lavavej | 0f901c7 | 2016-11-04 20:26:59 +0000 | [diff] [blame] | 18 | #include "test_macros.h" |
| 19 | |
Howard Hinnant | 94b2dd0 | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 20 | int main() |
| 21 | { |
| 22 | typedef std::divides<int> F; |
| 23 | const F f = F(); |
Marshall Clow | 66369c0 | 2015-01-07 20:31:06 +0000 | [diff] [blame] | 24 | 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 Hinnant | 94b2dd0 | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 27 | assert(f(36, 4) == 9); |
Stephan T. Lavavej | 0f901c7 | 2016-11-04 20:26:59 +0000 | [diff] [blame] | 28 | #if TEST_STD_VER > 11 |
Marshall Clow | 83c08b4 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 29 | 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 Clow | 3d5134dd | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 34 | |
| 35 | constexpr int foo = std::divides<int> () (3, 2); |
| 36 | static_assert ( foo == 1, "" ); |
| 37 | |
Stephan T. Lavavej | c255fa5 | 2016-12-08 21:38:01 +0000 | [diff] [blame] | 38 | constexpr double bar = std::divides<> () (3.0, 2); |
| 39 | static_assert ( bar == 1.5, "" ); // exact in binary |
Marshall Clow | 83c08b4 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 40 | #endif |
Howard Hinnant | 94b2dd0 | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 41 | } |