Update to upstream r216384.
This rebase skips the following patches in upstream: +37025e1b32Make the helper routines in string really be constexpr. This required a bit of refacoring in algorithm as well. Give them better names while we're at it. All of these are internal rotines; no visible functionality change. +164b297099Implement string_view from the library fundamentals TS (n4023). Also works in C++11 and 03, with reduced functionality (mostly in the area of constexpr) +e4694b4129Formatting improvements in the <string_view> synopsis suggested by RSmith. No functionality change. +3a61b30f3aMinor cleanup for string_view; mostly from suggestions by Richard Smith. Also, make the tests pass under c++03 +484728789estring_view enhancements. Move to the correct namespace. Better constexpr support (thanks to Richard for the suggestions). Update the tests to match this. Add <experimental/__config for experimental macros/etc to live. +b1a40264dc[libcxx] Add <experimental/utility> header for LFTS. +3ee7233c80[libcxx] expose experimental::erased_type for all standard versions. +67740670f9NFC. Remove trailing whitespace and tabs. +b9536101dcNFC. Move definition of _LIBCPP_ASSERT into __debug header and remove external include guards. +98c4e404ca. Revert "Turn off extern templates for most uses." Bug: 17255369 Change-Id: I629ff16275d50e4cc8767b253a2c0542468348d8
This commit is contained in:
@@ -17,6 +17,9 @@
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
#include "counting_predicates.hpp"
|
||||
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
#include <memory>
|
||||
|
||||
@@ -32,11 +35,43 @@ struct indirect_less
|
||||
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);
|
||||
std::make_heap(ia, ia+N, std::greater<int>());
|
||||
assert(std::is_heap(ia, ia+N, std::greater<int>()));
|
||||
}
|
||||
|
||||
// Ascending
|
||||
{
|
||||
binary_counting_predicate<std::greater<int>, int, int> pred ((std::greater<int>()));
|
||||
for (int i = 0; i < N; ++i)
|
||||
ia[i] = i;
|
||||
std::make_heap(ia, ia+N, std::ref(pred));
|
||||
assert(pred.count() <= 3*N);
|
||||
assert(std::is_heap(ia, ia+N, pred));
|
||||
}
|
||||
|
||||
// Descending
|
||||
{
|
||||
binary_counting_predicate<std::greater<int>, int, int> pred ((std::greater<int>()));
|
||||
for (int i = 0; i < N; ++i)
|
||||
ia[N-1-i] = i;
|
||||
std::make_heap(ia, ia+N, std::ref(pred));
|
||||
assert(pred.count() <= 3*N);
|
||||
assert(std::is_heap(ia, ia+N, pred));
|
||||
}
|
||||
|
||||
// Random
|
||||
{
|
||||
binary_counting_predicate<std::greater<int>, int, int> pred ((std::greater<int>()));
|
||||
std::random_shuffle(ia, ia+N);
|
||||
std::make_heap(ia, ia+N, std::ref(pred));
|
||||
assert(pred.count() <= 3*N);
|
||||
assert(std::is_heap(ia, ia+N, pred));
|
||||
}
|
||||
|
||||
delete [] ia;
|
||||
}
|
||||
|
||||
@@ -48,6 +83,8 @@ int main()
|
||||
test(3);
|
||||
test(10);
|
||||
test(1000);
|
||||
test(10000);
|
||||
test(100000);
|
||||
|
||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
{
|
||||
|
||||
@@ -27,12 +27,12 @@ test()
|
||||
int ia[] = {1, 2, 3, 4};
|
||||
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
|
||||
int ib[] = {1, 2, 3};
|
||||
assert(!std::lexicographical_compare(ia, ia+sa, ib, ib+2));
|
||||
assert(std::lexicographical_compare(ib, ib+2, ia, ia+sa));
|
||||
assert(!std::lexicographical_compare(ia, ia+sa, ib, ib+3));
|
||||
assert(std::lexicographical_compare(ib, ib+3, ia, ia+sa));
|
||||
assert(std::lexicographical_compare(ia, ia+sa, ib+1, ib+3));
|
||||
assert(!std::lexicographical_compare(ib+1, ib+3, ia, ia+sa));
|
||||
assert(!std::lexicographical_compare(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+2)));
|
||||
assert( std::lexicographical_compare(Iter1(ib), Iter1(ib+2), Iter2(ia), Iter2(ia+sa)));
|
||||
assert(!std::lexicographical_compare(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+3)));
|
||||
assert( std::lexicographical_compare(Iter1(ib), Iter1(ib+3), Iter2(ia), Iter2(ia+sa)));
|
||||
assert( std::lexicographical_compare(Iter1(ia), Iter1(ia+sa), Iter2(ib+1), Iter2(ib+3)));
|
||||
assert(!std::lexicographical_compare(Iter1(ib+1), Iter1(ib+3), Iter2(ia), Iter2(ia+sa)));
|
||||
}
|
||||
|
||||
int main()
|
||||
|
||||
@@ -31,12 +31,12 @@ test()
|
||||
int ib[] = {1, 2, 3};
|
||||
typedef std::greater<int> C;
|
||||
C c;
|
||||
assert(!std::lexicographical_compare(ia, ia+sa, ib, ib+2, c));
|
||||
assert(std::lexicographical_compare(ib, ib+2, ia, ia+sa, c));
|
||||
assert(!std::lexicographical_compare(ia, ia+sa, ib, ib+3, c));
|
||||
assert(std::lexicographical_compare(ib, ib+3, ia, ia+sa, c));
|
||||
assert(!std::lexicographical_compare(ia, ia+sa, ib+1, ib+3, c));
|
||||
assert(std::lexicographical_compare(ib+1, ib+3, ia, ia+sa, c));
|
||||
assert(!std::lexicographical_compare(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+2), c));
|
||||
assert( std::lexicographical_compare(Iter1(ib), Iter1(ib+2), Iter2(ia), Iter2(ia+sa), c));
|
||||
assert(!std::lexicographical_compare(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+3), c));
|
||||
assert( std::lexicographical_compare(Iter1(ib), Iter1(ib+3), Iter2(ia), Iter2(ia+sa), c));
|
||||
assert(!std::lexicographical_compare(Iter1(ia), Iter1(ia+sa), Iter2(ib+1), Iter2(ib+3), c));
|
||||
assert( std::lexicographical_compare(Iter1(ib+1), Iter1(ib+3), Iter2(ia), Iter2(ia+sa), c));
|
||||
}
|
||||
|
||||
int main()
|
||||
|
||||
@@ -58,10 +58,28 @@ test()
|
||||
test<Iter>(1000);
|
||||
}
|
||||
|
||||
template <class Iter, class Pred>
|
||||
void test_eq0(Iter first, Iter last, Pred p)
|
||||
{
|
||||
assert(first == std::max_element(first, last, p));
|
||||
}
|
||||
|
||||
void test_eq()
|
||||
{
|
||||
const size_t N = 10;
|
||||
int* a = new int[N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
a[i] = 10; // all the same
|
||||
test_eq0(a, a+N, std::less<int>());
|
||||
test_eq0(a, a+N, std::greater<int>());
|
||||
delete [] a;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test<forward_iterator<const int*> >();
|
||||
test<bidirectional_iterator<const int*> >();
|
||||
test<random_access_iterator<const int*> >();
|
||||
test<const int*>();
|
||||
test_eq();
|
||||
}
|
||||
|
||||
@@ -58,10 +58,28 @@ test()
|
||||
test<Iter>(1000);
|
||||
}
|
||||
|
||||
template <class Iter, class Pred>
|
||||
void test_eq0(Iter first, Iter last, Pred p)
|
||||
{
|
||||
assert(first == std::min_element(first, last, p));
|
||||
}
|
||||
|
||||
void test_eq()
|
||||
{
|
||||
const size_t N = 10;
|
||||
int* a = new int[N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
a[i] = 10; // all the same
|
||||
test_eq0(a, a+N, std::less<int>());
|
||||
test_eq0(a, a+N, std::greater<int>());
|
||||
delete [] a;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test<forward_iterator<const int*> >();
|
||||
test<bidirectional_iterator<const int*> >();
|
||||
test<random_access_iterator<const int*> >();
|
||||
test<const int*>();
|
||||
test_eq();
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ int main()
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
// Note that you can't take a reference to a local var, since
|
||||
// it's address is not a compile-time constant.
|
||||
// its address is not a compile-time constant.
|
||||
constexpr static int x = 1;
|
||||
constexpr static int y = 0;
|
||||
constexpr auto p1 = std::minmax (x, y);
|
||||
|
||||
@@ -51,7 +51,7 @@ int main()
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
// Note that you can't take a reference to a local var, since
|
||||
// it's address is not a compile-time constant.
|
||||
// its address is not a compile-time constant.
|
||||
constexpr static int x = 1;
|
||||
constexpr static int y = 0;
|
||||
constexpr auto p1 = std::minmax(x, y, std::greater<>());
|
||||
|
||||
Reference in New Issue
Block a user