libcxx initial import
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@103490 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <algorithm>
|
||||
|
||||
// template<ForwardIterator Iter, class T>
|
||||
// requires HasLess<T, Iter::value_type>
|
||||
// && HasLess<Iter::value_type, T>
|
||||
// bool
|
||||
// binary_search(Iter first, Iter last, const T& value);
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
#include "../../../iterators.h"
|
||||
|
||||
template <class Iter, class T>
|
||||
void
|
||||
test(Iter first, Iter last, const T& value, bool x)
|
||||
{
|
||||
assert(std::binary_search(first, last, value) == x);
|
||||
}
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test()
|
||||
{
|
||||
const unsigned N = 1000;
|
||||
const unsigned M = 10;
|
||||
std::vector<int> v(N);
|
||||
int x = 0;
|
||||
for (int i = 0; i < v.size(); ++i)
|
||||
{
|
||||
v[i] = x;
|
||||
if (++x == M)
|
||||
x = 0;
|
||||
}
|
||||
std::sort(v.begin(), v.end());
|
||||
for (x = 0; x < M; ++x)
|
||||
test(Iter(v.data()), Iter(v.data()+v.size()), x, true);
|
||||
test(Iter(v.data()), Iter(v.data()+v.size()), -1, false);
|
||||
test(Iter(v.data()), Iter(v.data()+v.size()), M, false);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int d[] = {0, 2, 4, 6};
|
||||
for (int* e = d; e <= d+4; ++e)
|
||||
for (int x = -1; x <= 7; ++x)
|
||||
test(d, e, x, (x % 2 == 0) && ((e-d)*2 > x));
|
||||
|
||||
test<forward_iterator<const int*> >();
|
||||
test<bidirectional_iterator<const int*> >();
|
||||
test<random_access_iterator<const int*> >();
|
||||
test<const int*>();
|
||||
}
|
@@ -0,0 +1,64 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <algorithm>
|
||||
|
||||
// template<ForwardIterator Iter, class T, CopyConstructible Compare>
|
||||
// requires Predicate<Compare, T, Iter::value_type>
|
||||
// && Predicate<Compare, Iter::value_type, T>
|
||||
// bool
|
||||
// binary_search(Iter first, Iter last, const T& value, Compare comp);
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
#include "../../../iterators.h"
|
||||
|
||||
template <class Iter, class T>
|
||||
void
|
||||
test(Iter first, Iter last, const T& value, bool x)
|
||||
{
|
||||
assert(std::binary_search(first, last, value, std::greater<int>()) == x);
|
||||
}
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test()
|
||||
{
|
||||
const unsigned N = 1000;
|
||||
const unsigned M = 10;
|
||||
std::vector<int> v(N);
|
||||
int x = 0;
|
||||
for (int i = 0; i < v.size(); ++i)
|
||||
{
|
||||
v[i] = x;
|
||||
if (++x == M)
|
||||
x = 0;
|
||||
}
|
||||
std::sort(v.begin(), v.end(), std::greater<int>());
|
||||
for (x = 0; x < M; ++x)
|
||||
test(Iter(v.data()), Iter(v.data()+v.size()), x, true);
|
||||
test(Iter(v.data()), Iter(v.data()+v.size()), -1, false);
|
||||
test(Iter(v.data()), Iter(v.data()+v.size()), M, false);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int d[] = {6, 4, 2, 0};
|
||||
for (int* e = d; e <= d+4; ++e)
|
||||
for (int x = -1; x <= 7; ++x)
|
||||
test(d, e, x, (x % 2 == 0) && e != d && (-2*(e-d) + 8 <= x));
|
||||
|
||||
test<forward_iterator<const int*> >();
|
||||
test<bidirectional_iterator<const int*> >();
|
||||
test<random_access_iterator<const int*> >();
|
||||
test<const int*>();
|
||||
}
|
@@ -0,0 +1,69 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <algorithm>
|
||||
|
||||
// template<ForwardIterator Iter, class T>
|
||||
// requires HasLess<T, Iter::value_type>
|
||||
// && HasLess<Iter::value_type, T>
|
||||
// pair<Iter, Iter>
|
||||
// equal_range(Iter first, Iter last, const T& value);
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
#include "../../../iterators.h"
|
||||
|
||||
template <class Iter, class T>
|
||||
void
|
||||
test(Iter first, Iter last, const T& value)
|
||||
{
|
||||
std::pair<Iter, Iter> i = std::equal_range(first, last, value);
|
||||
for (Iter j = first; j != i.first; ++j)
|
||||
assert(*j < value);
|
||||
for (Iter j = i.first; j != last; ++j)
|
||||
assert(!(*j < value));
|
||||
for (Iter j = first; j != i.second; ++j)
|
||||
assert(!(value < *j));
|
||||
for (Iter j = i.second; j != last; ++j)
|
||||
assert(value < *j);
|
||||
}
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test()
|
||||
{
|
||||
const unsigned N = 1000;
|
||||
const unsigned M = 10;
|
||||
std::vector<int> v(N);
|
||||
int x = 0;
|
||||
for (int i = 0; i < v.size(); ++i)
|
||||
{
|
||||
v[i] = x;
|
||||
if (++x == M)
|
||||
x = 0;
|
||||
}
|
||||
std::sort(v.begin(), v.end());
|
||||
for (x = 0; x <= M; ++x)
|
||||
test(Iter(v.data()), Iter(v.data()+v.size()), x);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int d[] = {0, 1, 2, 3};
|
||||
for (int* e = d; e <= d+4; ++e)
|
||||
for (int x = -1; x <= 4; ++x)
|
||||
test(d, e, x);
|
||||
|
||||
test<forward_iterator<const int*> >();
|
||||
test<bidirectional_iterator<const int*> >();
|
||||
test<random_access_iterator<const int*> >();
|
||||
test<const int*>();
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <algorithm>
|
||||
|
||||
// template<ForwardIterator Iter, class T, CopyConstructible Compare>
|
||||
// requires Predicate<Compare, T, Iter::value_type>
|
||||
// && Predicate<Compare, Iter::value_type, T>
|
||||
// pair<Iter, Iter>
|
||||
// equal_range(Iter first, Iter last, const T& value, Compare comp);
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
#include "../../../iterators.h"
|
||||
|
||||
template <class Iter, class T>
|
||||
void
|
||||
test(Iter first, Iter last, const T& value)
|
||||
{
|
||||
std::pair<Iter, Iter> i = std::equal_range(first, last, value, std::greater<int>());
|
||||
for (Iter j = first; j != i.first; ++j)
|
||||
assert(std::greater<int>()(*j, value));
|
||||
for (Iter j = i.first; j != last; ++j)
|
||||
assert(!std::greater<int>()(*j, value));
|
||||
for (Iter j = first; j != i.second; ++j)
|
||||
assert(!std::greater<int>()(value, *j));
|
||||
for (Iter j = i.second; j != last; ++j)
|
||||
assert(std::greater<int>()(value, *j));
|
||||
}
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test()
|
||||
{
|
||||
const unsigned N = 1000;
|
||||
const unsigned M = 10;
|
||||
std::vector<int> v(N);
|
||||
int x = 0;
|
||||
for (int i = 0; i < v.size(); ++i)
|
||||
{
|
||||
v[i] = x;
|
||||
if (++x == M)
|
||||
x = 0;
|
||||
}
|
||||
std::sort(v.begin(), v.end(), std::greater<int>());
|
||||
for (x = 0; x <= M; ++x)
|
||||
test(Iter(v.data()), Iter(v.data()+v.size()), x);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int d[] = {3, 2, 1, 0};
|
||||
for (int* e = d; e <= d+4; ++e)
|
||||
for (int x = -1; x <= 4; ++x)
|
||||
test(d, e, x);
|
||||
|
||||
test<forward_iterator<const int*> >();
|
||||
test<bidirectional_iterator<const int*> >();
|
||||
test<random_access_iterator<const int*> >();
|
||||
test<const int*>();
|
||||
}
|
@@ -0,0 +1,64 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <algorithm>
|
||||
|
||||
// template<ForwardIterator Iter, class T>
|
||||
// requires HasLess<Iter::value_type, T>
|
||||
// Iter
|
||||
// lower_bound(Iter first, Iter last, const T& value);
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
#include "../../../iterators.h"
|
||||
|
||||
template <class Iter, class T>
|
||||
void
|
||||
test(Iter first, Iter last, const T& value)
|
||||
{
|
||||
Iter i = std::lower_bound(first, last, value);
|
||||
for (Iter j = first; j != i; ++j)
|
||||
assert(*j < value);
|
||||
for (Iter j = i; j != last; ++j)
|
||||
assert(!(*j < value));
|
||||
}
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test()
|
||||
{
|
||||
const unsigned N = 1000;
|
||||
const unsigned M = 10;
|
||||
std::vector<int> v(N);
|
||||
int x = 0;
|
||||
for (int i = 0; i < v.size(); ++i)
|
||||
{
|
||||
v[i] = x;
|
||||
if (++x == M)
|
||||
x = 0;
|
||||
}
|
||||
std::sort(v.begin(), v.end());
|
||||
for (x = 0; x <= M; ++x)
|
||||
test(Iter(v.data()), Iter(v.data()+v.size()), x);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int d[] = {0, 1, 2, 3};
|
||||
for (int* e = d; e <= d+4; ++e)
|
||||
for (int x = -1; x <= 4; ++x)
|
||||
test(d, e, x);
|
||||
|
||||
test<forward_iterator<const int*> >();
|
||||
test<bidirectional_iterator<const int*> >();
|
||||
test<random_access_iterator<const int*> >();
|
||||
test<const int*>();
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <algorithm>
|
||||
|
||||
// template<ForwardIterator Iter, class T>
|
||||
// requires HasLess<Iter::value_type, T>
|
||||
// Iter
|
||||
// lower_bound(Iter first, Iter last, const T& value);
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
#include "../../../iterators.h"
|
||||
|
||||
template <class Iter, class T>
|
||||
void
|
||||
test(Iter first, Iter last, const T& value)
|
||||
{
|
||||
Iter i = std::lower_bound(first, last, value, std::greater<int>());
|
||||
for (Iter j = first; j != i; ++j)
|
||||
assert(std::greater<int>()(*j, value));
|
||||
for (Iter j = i; j != last; ++j)
|
||||
assert(!std::greater<int>()(*j, value));
|
||||
}
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test()
|
||||
{
|
||||
const unsigned N = 1000;
|
||||
const unsigned M = 10;
|
||||
std::vector<int> v(N);
|
||||
int x = 0;
|
||||
for (int i = 0; i < v.size(); ++i)
|
||||
{
|
||||
v[i] = x;
|
||||
if (++x == M)
|
||||
x = 0;
|
||||
}
|
||||
std::sort(v.begin(), v.end(), std::greater<int>());
|
||||
for (x = 0; x <= M; ++x)
|
||||
test(Iter(v.data()), Iter(v.data()+v.size()), x);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int d[] = {3, 2, 1, 0};
|
||||
for (int* e = d; e <= d+4; ++e)
|
||||
for (int x = -1; x <= 4; ++x)
|
||||
test(d, e, x);
|
||||
|
||||
test<forward_iterator<const int*> >();
|
||||
test<bidirectional_iterator<const int*> >();
|
||||
test<random_access_iterator<const int*> >();
|
||||
test<const int*>();
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
@@ -0,0 +1,64 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <algorithm>
|
||||
|
||||
// template<ForwardIterator Iter, class T>
|
||||
// requires HasLess<T, Iter::value_type>
|
||||
// Iter
|
||||
// upper_bound(Iter first, Iter last, const T& value);
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
#include "../../../iterators.h"
|
||||
|
||||
template <class Iter, class T>
|
||||
void
|
||||
test(Iter first, Iter last, const T& value)
|
||||
{
|
||||
Iter i = std::upper_bound(first, last, value);
|
||||
for (Iter j = first; j != i; ++j)
|
||||
assert(!(value < *j));
|
||||
for (Iter j = i; j != last; ++j)
|
||||
assert(value < *j);
|
||||
}
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test()
|
||||
{
|
||||
const unsigned N = 1000;
|
||||
const unsigned M = 10;
|
||||
std::vector<int> v(N);
|
||||
int x = 0;
|
||||
for (int i = 0; i < v.size(); ++i)
|
||||
{
|
||||
v[i] = x;
|
||||
if (++x == M)
|
||||
x = 0;
|
||||
}
|
||||
std::sort(v.begin(), v.end());
|
||||
for (x = 0; x <= M; ++x)
|
||||
test(Iter(v.data()), Iter(v.data()+v.size()), x);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int d[] = {0, 1, 2, 3};
|
||||
for (int* e = d; e <= d+4; ++e)
|
||||
for (int x = -1; x <= 4; ++x)
|
||||
test(d, e, x);
|
||||
|
||||
test<forward_iterator<const int*> >();
|
||||
test<bidirectional_iterator<const int*> >();
|
||||
test<random_access_iterator<const int*> >();
|
||||
test<const int*>();
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <algorithm>
|
||||
|
||||
// template<ForwardIterator Iter, class T, Predicate<auto, T, Iter::value_type> Compare>
|
||||
// requires CopyConstructible<Compare>
|
||||
// Iter
|
||||
// upper_bound(Iter first, Iter last, const T& value, Compare comp);
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
#include "../../../iterators.h"
|
||||
|
||||
template <class Iter, class T>
|
||||
void
|
||||
test(Iter first, Iter last, const T& value)
|
||||
{
|
||||
Iter i = std::upper_bound(first, last, value, std::greater<int>());
|
||||
for (Iter j = first; j != i; ++j)
|
||||
assert(!std::greater<int>()(value, *j));
|
||||
for (Iter j = i; j != last; ++j)
|
||||
assert(std::greater<int>()(value, *j));
|
||||
}
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test()
|
||||
{
|
||||
const unsigned N = 1000;
|
||||
const unsigned M = 10;
|
||||
std::vector<int> v(N);
|
||||
int x = 0;
|
||||
for (int i = 0; i < v.size(); ++i)
|
||||
{
|
||||
v[i] = x;
|
||||
if (++x == M)
|
||||
x = 0;
|
||||
}
|
||||
std::sort(v.begin(), v.end(), std::greater<int>());
|
||||
for (x = 0; x <= M; ++x)
|
||||
test(Iter(v.data()), Iter(v.data()+v.size()), x);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int d[] = {3, 2, 1, 0};
|
||||
for (int* e = d; e <= d+4; ++e)
|
||||
for (int x = -1; x <= 4; ++x)
|
||||
test(d, e, x);
|
||||
|
||||
test<forward_iterator<const int*> >();
|
||||
test<bidirectional_iterator<const int*> >();
|
||||
test<random_access_iterator<const int*> >();
|
||||
test<const int*>();
|
||||
}
|
Reference in New Issue
Block a user