xref: /llvm-project/libcxx/test/std/utilities/function.objects/arithmetic.operations/divides.pass.cpp (revision dc066888bd98c0500ca7b590317dc91ccce0fd38)
15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier 
9*dc066888SArthur O'Dwyer // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
10*dc066888SArthur O'Dwyer 
115a83710eSEric Fiselier // <functional>
125a83710eSEric Fiselier 
135a83710eSEric Fiselier // divides
145a83710eSEric Fiselier 
155a83710eSEric Fiselier #include <functional>
165a83710eSEric Fiselier #include <type_traits>
175a83710eSEric Fiselier #include <cassert>
185a83710eSEric Fiselier 
190f901c7eSStephan T. Lavavej #include "test_macros.h"
200f901c7eSStephan T. Lavavej 
main(int,char **)212df59c50SJF Bastien int main(int, char**)
225a83710eSEric Fiselier {
235a83710eSEric Fiselier     typedef std::divides<int> F;
245a83710eSEric Fiselier     const F f = F();
25*dc066888SArthur O'Dwyer #if TEST_STD_VER <= 17
2666369c03SMarshall Clow     static_assert((std::is_same<int, F::first_argument_type>::value), "" );
2766369c03SMarshall Clow     static_assert((std::is_same<int, F::second_argument_type>::value), "" );
2866369c03SMarshall Clow     static_assert((std::is_same<int, F::result_type>::value), "" );
29*dc066888SArthur O'Dwyer #endif
305a83710eSEric Fiselier     assert(f(36, 4) == 9);
310f901c7eSStephan T. Lavavej #if TEST_STD_VER > 11
325a83710eSEric Fiselier     typedef std::divides<> F2;
335a83710eSEric Fiselier     const F2 f2 = F2();
345a83710eSEric Fiselier     assert(f2(36, 4) == 9);
355a83710eSEric Fiselier     assert(f2(36.0, 4) == 9);
365a83710eSEric Fiselier     assert(f2(18, 4.0) == 4.5); // exact in binary
375a83710eSEric Fiselier 
385a83710eSEric Fiselier     constexpr int foo = std::divides<int> () (3, 2);
395a83710eSEric Fiselier     static_assert ( foo == 1, "" );
405a83710eSEric Fiselier 
41c255fa5eSStephan T. Lavavej     constexpr double bar = std::divides<> () (3.0, 2);
42c255fa5eSStephan T. Lavavej     static_assert ( bar == 1.5, "" ); // exact in binary
435a83710eSEric Fiselier #endif
442df59c50SJF Bastien 
452df59c50SJF Bastien   return 0;
465a83710eSEric Fiselier }
47