libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

min_comp.pass.cpp (1373B)


      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 //   min(const T& a, const T& b, Compare comp);
     16 
     17 #include <algorithm>
     18 #include <functional>
     19 #include <cassert>
     20 
     21 #include "test_macros.h"
     22 
     23 template <class T, class C>
     24 void
     25 test(const T& a, const T& b, C c, const T& x)
     26 {
     27     assert(&std::min(a, b, c) == &x);
     28 }
     29 
     30 int main()
     31 {
     32     {
     33     int x = 0;
     34     int y = 0;
     35     test(x, y, std::greater<int>(), x);
     36     test(y, x, std::greater<int>(), y);
     37     }
     38     {
     39     int x = 0;
     40     int y = 1;
     41     test(x, y, std::greater<int>(), y);
     42     test(y, x, std::greater<int>(), y);
     43     }
     44     {
     45     int x = 1;
     46     int y = 0;
     47     test(x, y, std::greater<int>(), x);
     48     test(y, x, std::greater<int>(), x);
     49     }
     50 #if TEST_STD_VER >= 14
     51     {
     52     constexpr int x = 1;
     53     constexpr int y = 0;
     54     static_assert(std::min(x, y, std::greater<int>()) == x, "" );
     55     static_assert(std::min(y, x, std::greater<int>()) == x, "" );
     56     }
     57 #endif
     58 }