Home | History | Annotate | Download | only in alg.min.max
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <algorithm>
     11 
     12 // template<class T, StrictWeakOrder<auto, T> Compare>
     13 //   requires !SameType<T, Compare> && CopyConstructible<Compare>
     14 //   const T&
     15 //   max(const T& a, const T& b, Compare comp);
     16 
     17 #include <algorithm>
     18 #include <functional>
     19 #include <cassert>
     20 
     21 template <class T, class C>
     22 void
     23 test(const T& a, const T& b, C c, const T& x)
     24 {
     25     assert(&std::max(a, b, c) == &x);
     26 }
     27 
     28 int main()
     29 {
     30     {
     31     int x = 0;
     32     int y = 0;
     33     test(x, y, std::greater<int>(), x);
     34     test(y, x, std::greater<int>(), y);
     35     }
     36     {
     37     int x = 0;
     38     int y = 1;
     39     test(x, y, std::greater<int>(), x);
     40     test(y, x, std::greater<int>(), x);
     41     }
     42     {
     43     int x = 1;
     44     int y = 0;
     45     test(x, y, std::greater<int>(), y);
     46     test(y, x, std::greater<int>(), y);
     47     }
     48 #if _LIBCPP_STD_VER > 11
     49     {
     50     constexpr int x = 1;
     51     constexpr int y = 0;
     52     static_assert(std::max(x, y, std::greater<int>()) == y, "" );
     53     static_assert(std::max(y, x, std::greater<int>()) == y, "" );
     54     }
     55 #endif
     56 }
     57