Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <algorithm> |
| 11 | |
Howard Hinnant | eb564e7 | 2010-08-22 00:08:10 +0000 | [diff] [blame] | 12 | // template<RandomAccessIterator Iter, StrictWeakOrder<auto, Iter::value_type> Compare> |
| 13 | // requires ShuffleIterator<Iter> |
| 14 | // && CopyConstructible<Compare> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 15 | // void |
| 16 | // sort(Iter first, Iter last, Compare comp); |
| 17 | |
| 18 | #include <algorithm> |
| 19 | #include <functional> |
| 20 | #include <vector> |
| 21 | #include <cassert> |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 22 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 23 | #include <memory> |
| 24 | |
| 25 | struct indirect_less |
| 26 | { |
| 27 | template <class P> |
| 28 | bool operator()(const P& x, const P& y) |
| 29 | {return *x < *y;} |
| 30 | }; |
| 31 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 32 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 33 | |
| 34 | int main() |
| 35 | { |
| 36 | { |
| 37 | std::vector<int> v(1000); |
| 38 | for (int i = 0; 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 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 45 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 46 | { |
| 47 | std::vector<std::unique_ptr<int> > v(1000); |
| 48 | for (int i = 0; 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 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 56 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 57 | } |