//===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // template // requires ShuffleIterator // && LessThanComparable // void // push_heap(Iter first, Iter last); #include #include #include #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES #include struct indirect_less { template bool operator()(const P& x, const P& y) {return *x < *y;} }; #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES void test(unsigned N) { int* ia = new int [N]; for (int i = 0; i < N; ++i) ia[i] = i; std::random_shuffle(ia, ia+N); for (int i = 0; i <= N; ++i) { std::push_heap(ia, ia+i, std::greater()); assert(std::is_heap(ia, ia+i, std::greater())); } delete [] ia; } int main() { test(1000); #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES { const int N = 1000; std::unique_ptr* ia = new std::unique_ptr [N]; for (int i = 0; i < N; ++i) ia[i].reset(new int(i)); std::random_shuffle(ia, ia+N); for (int i = 0; i <= N; ++i) { std::push_heap(ia, ia+i, indirect_less()); assert(std::is_heap(ia, ia+i, indirect_less())); } delete [] ia; } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES }