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<RandomAccessIterator Iter, StrictWeakOrder<auto, Iter::value_type> Compare> 13 // requires ShuffleIterator<Iter> 14 // && CopyConstructible<Compare> 15 // void 16 // sort(Iter first, Iter last, Compare comp); 17 18 #include <algorithm> 19 #include <functional> 20 #include <vector> 21 #include <cassert> 22 #include <cstddef> 23 #include <memory> 24 25 #include "test_macros.h" 26 27 struct indirect_less 28 { 29 template <class P> 30 bool operator()(const P& x, const P& y) 31 {return *x < *y;} 32 }; 33 34 int main() 35 { 36 { 37 std::vector<int> v(1000); 38 for (int i = 0; static_cast<std::size_t>(i) < v.size(); ++i) 39 v[i] = i; 40 std::sort(v.begin(), v.end(), std::greater<int>()); 41 std::reverse(v.begin(), v.end()); 42 assert(std::is_sorted(v.begin(), v.end())); 43 } 44 45 #if TEST_STD_VER >= 11 46 { 47 std::vector<std::unique_ptr<int> > v(1000); 48 for (int i = 0; static_cast<std::size_t>(i) < v.size(); ++i) 49 v[i].reset(new int(i)); 50 std::sort(v.begin(), v.end(), indirect_less()); 51 assert(std::is_sorted(v.begin(), v.end(), indirect_less())); 52 assert(*v[0] == 0); 53 assert(*v[1] == 1); 54 assert(*v[2] == 2); 55 } 56 #endif 57 } 58