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,183 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <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>
|
||||
// requires LessThanComparable<Iter::value_type>
|
||||
// bool
|
||||
// is_sorted(Iter first, Iter last);
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
#include "../../../iterators.h"
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test()
|
||||
{
|
||||
{
|
||||
int a[] = {0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted(Iter(a), Iter(a)));
|
||||
assert(std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
|
||||
{
|
||||
int a[] = {0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
|
||||
{
|
||||
int a[] = {0, 0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
|
||||
{
|
||||
int a[] = {0, 0, 0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 0, 0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 0, 1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 0, 1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1, 0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1, 0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1, 1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1, 1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0, 0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0, 0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0, 1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0, 1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1, 0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1, 0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1, 1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1, 1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted(Iter(a), Iter(a+sa)));
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test<forward_iterator<const int*> >();
|
||||
test<bidirectional_iterator<const int*> >();
|
||||
test<random_access_iterator<const int*> >();
|
||||
test<const int*>();
|
||||
}
|
@@ -0,0 +1,184 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <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, StrictWeakOrder<auto, Iter::value_type> Compare>
|
||||
// requires CopyConstructible<Compare>
|
||||
// bool
|
||||
// is_sorted(Iter first, Iter last, Compare comp);
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
#include "../../../iterators.h"
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test()
|
||||
{
|
||||
{
|
||||
int a[] = {0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted(Iter(a), Iter(a)));
|
||||
assert(std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
|
||||
{
|
||||
int a[] = {0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
|
||||
{
|
||||
int a[] = {0, 0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
|
||||
{
|
||||
int a[] = {0, 0, 0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 0, 0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 0, 1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 0, 1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1, 0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1, 0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1, 1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1, 1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0, 0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0, 0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0, 1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0, 1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1, 0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1, 0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(!std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1, 1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1, 1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted(Iter(a), Iter(a+sa), std::greater<int>()));
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test<forward_iterator<const int*> >();
|
||||
test<bidirectional_iterator<const int*> >();
|
||||
test<random_access_iterator<const int*> >();
|
||||
test<const int*>();
|
||||
}
|
@@ -0,0 +1,183 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <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>
|
||||
// requires LessThanComparable<Iter::value_type>
|
||||
// Iter
|
||||
// is_sorted_until(Iter first, Iter last);
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
#include "../../../iterators.h"
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test()
|
||||
{
|
||||
{
|
||||
int a[] = {0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a)) == Iter(a));
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+sa));
|
||||
}
|
||||
|
||||
{
|
||||
int a[] = {0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+sa));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+sa));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+1));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+sa));
|
||||
}
|
||||
|
||||
{
|
||||
int a[] = {0, 0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+sa));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+sa));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+2));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+sa));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+1));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+1));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+2));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+sa));
|
||||
}
|
||||
|
||||
{
|
||||
int a[] = {0, 0, 0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+sa));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 0, 0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+sa));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 0, 1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+3));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 0, 1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+sa));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1, 0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+2));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1, 0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+2));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1, 1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+3));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1, 1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+sa));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0, 0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+1));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0, 0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+1));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0, 1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+1));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0, 1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+1));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1, 0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+2));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1, 0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+2));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1, 1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+3));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1, 1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa)) == Iter(a+sa));
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test<forward_iterator<const int*> >();
|
||||
test<bidirectional_iterator<const int*> >();
|
||||
test<random_access_iterator<const int*> >();
|
||||
test<const int*>();
|
||||
}
|
@@ -0,0 +1,184 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <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, StrictWeakOrder<auto, Iter::value_type> Compare>
|
||||
// requires CopyConstructible<Compare>
|
||||
// Iter
|
||||
// is_sorted_until(Iter first, Iter last, Compare comp);
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
#include "../../../iterators.h"
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test()
|
||||
{
|
||||
{
|
||||
int a[] = {0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a), std::greater<int>()) == Iter(a));
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+sa));
|
||||
}
|
||||
|
||||
{
|
||||
int a[] = {0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+sa));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+1));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+sa));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+sa));
|
||||
}
|
||||
|
||||
{
|
||||
int a[] = {0, 0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+sa));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+2));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+1));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+1));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+sa));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+2));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+sa));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+sa));
|
||||
}
|
||||
|
||||
{
|
||||
int a[] = {0, 0, 0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+sa));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 0, 0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+3));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 0, 1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+2));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 0, 1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+2));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1, 0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+1));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1, 0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+1));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1, 1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+1));
|
||||
}
|
||||
{
|
||||
int a[] = {0, 1, 1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+1));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0, 0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+sa));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0, 0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+3));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0, 1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+2));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 0, 1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+2));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1, 0, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+sa));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1, 0, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+3));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1, 1, 0};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+sa));
|
||||
}
|
||||
{
|
||||
int a[] = {1, 1, 1, 1};
|
||||
unsigned sa = sizeof(a) / sizeof(a[0]);
|
||||
assert(std::is_sorted_until(Iter(a), Iter(a+sa), std::greater<int>()) == Iter(a+sa));
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test<forward_iterator<const int*> >();
|
||||
test<bidirectional_iterator<const int*> >();
|
||||
test<random_access_iterator<const int*> >();
|
||||
test<const int*>();
|
||||
}
|
12
test/algorithms/alg.sorting/alg.sort/nothing_to_do.pass.cpp
Normal file
12
test/algorithms/alg.sorting/alg.sort/nothing_to_do.pass.cpp
Normal file
@@ -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,86 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <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<InputIterator InIter, RandomAccessIterator RAIter>
|
||||
// requires ShuffleIterator<RAIter>
|
||||
// && OutputIterator<RAIter, InIter::reference>
|
||||
// && HasLess<InIter::value_type, RAIter::value_type>
|
||||
// && LessThanComparable<RAIter::value_type>
|
||||
// RAIter
|
||||
// partial_sort_copy(InIter first, InIter last, RAIter result_first, RAIter result_last);
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
#include "../../../iterators.h"
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test_larger_sorts(unsigned N, unsigned M)
|
||||
{
|
||||
int* input = new int[N];
|
||||
int* output = new int[M];
|
||||
for (int i = 0; i < N; ++i)
|
||||
input[i] = i;
|
||||
std::random_shuffle(input, input+N);
|
||||
int* r = std::partial_sort_copy(Iter(input), Iter(input+N), output, output+M);
|
||||
int* e = output + std::min(N, M);
|
||||
assert(r == e);
|
||||
int i = 0;
|
||||
for (int* x = output; x < e; ++x, ++i)
|
||||
assert(*x == i);
|
||||
delete [] output;
|
||||
delete [] input;
|
||||
}
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test_larger_sorts(unsigned N)
|
||||
{
|
||||
test_larger_sorts<Iter>(N, 0);
|
||||
test_larger_sorts<Iter>(N, 1);
|
||||
test_larger_sorts<Iter>(N, 2);
|
||||
test_larger_sorts<Iter>(N, 3);
|
||||
test_larger_sorts<Iter>(N, N/2-1);
|
||||
test_larger_sorts<Iter>(N, N/2);
|
||||
test_larger_sorts<Iter>(N, N/2+1);
|
||||
test_larger_sorts<Iter>(N, N-2);
|
||||
test_larger_sorts<Iter>(N, N-1);
|
||||
test_larger_sorts<Iter>(N, N);
|
||||
test_larger_sorts<Iter>(N, N+1000);
|
||||
}
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test()
|
||||
{
|
||||
test_larger_sorts<Iter>(0, 100);
|
||||
test_larger_sorts<Iter>(10);
|
||||
test_larger_sorts<Iter>(256);
|
||||
test_larger_sorts<Iter>(257);
|
||||
test_larger_sorts<Iter>(499);
|
||||
test_larger_sorts<Iter>(500);
|
||||
test_larger_sorts<Iter>(997);
|
||||
test_larger_sorts<Iter>(1000);
|
||||
test_larger_sorts<Iter>(1009);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int i = 0;
|
||||
std::partial_sort_copy(&i, &i, &i, &i+5);
|
||||
assert(i == 0);
|
||||
test<input_iterator<const int*> >();
|
||||
test<forward_iterator<const int*> >();
|
||||
test<bidirectional_iterator<const int*> >();
|
||||
test<random_access_iterator<const int*> >();
|
||||
test<const int*>();
|
||||
}
|
@@ -0,0 +1,90 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <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<InputIterator InIter, RandomAccessIterator RAIter, class Compare>
|
||||
// requires ShuffleIterator<RAIter>
|
||||
// && OutputIterator<RAIter, InIter::reference>
|
||||
// && Predicate<Compare, InIter::value_type, RAIter::value_type>
|
||||
// && StrictWeakOrder<Compare, RAIter::value_type>}
|
||||
// && CopyConstructible<Compare>
|
||||
// RAIter
|
||||
// partial_sort_copy(InIter first, InIter last,
|
||||
// RAIter result_first, RAIter result_last, Compare comp);
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
#include "../../../iterators.h"
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test_larger_sorts(unsigned N, unsigned M)
|
||||
{
|
||||
int* input = new int[N];
|
||||
int* output = new int[M];
|
||||
for (int i = 0; i < N; ++i)
|
||||
input[i] = i;
|
||||
std::random_shuffle(input, input+N);
|
||||
int* r = std::partial_sort_copy(Iter(input), Iter(input+N), output, output+M,
|
||||
std::greater<int>());
|
||||
int* e = output + std::min(N, M);
|
||||
assert(r == e);
|
||||
int i = 0;
|
||||
for (int* x = output; x < e; ++x, ++i)
|
||||
assert(*x == N-i-1);
|
||||
delete [] output;
|
||||
delete [] input;
|
||||
}
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test_larger_sorts(unsigned N)
|
||||
{
|
||||
test_larger_sorts<Iter>(N, 0);
|
||||
test_larger_sorts<Iter>(N, 1);
|
||||
test_larger_sorts<Iter>(N, 2);
|
||||
test_larger_sorts<Iter>(N, 3);
|
||||
test_larger_sorts<Iter>(N, N/2-1);
|
||||
test_larger_sorts<Iter>(N, N/2);
|
||||
test_larger_sorts<Iter>(N, N/2+1);
|
||||
test_larger_sorts<Iter>(N, N-2);
|
||||
test_larger_sorts<Iter>(N, N-1);
|
||||
test_larger_sorts<Iter>(N, N);
|
||||
test_larger_sorts<Iter>(N, N+1000);
|
||||
}
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test()
|
||||
{
|
||||
test_larger_sorts<Iter>(0, 100);
|
||||
test_larger_sorts<Iter>(10);
|
||||
test_larger_sorts<Iter>(256);
|
||||
test_larger_sorts<Iter>(257);
|
||||
test_larger_sorts<Iter>(499);
|
||||
test_larger_sorts<Iter>(500);
|
||||
test_larger_sorts<Iter>(997);
|
||||
test_larger_sorts<Iter>(1000);
|
||||
test_larger_sorts<Iter>(1009);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int i = 0;
|
||||
std::partial_sort_copy(&i, &i, &i, &i+5);
|
||||
assert(i == 0);
|
||||
test<input_iterator<const int*> >();
|
||||
test<forward_iterator<const int*> >();
|
||||
test<bidirectional_iterator<const int*> >();
|
||||
test<random_access_iterator<const int*> >();
|
||||
test<const int*>();
|
||||
}
|
@@ -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<RandomAccessIterator Iter>
|
||||
// requires ShuffleIterator<Iter>
|
||||
// && LessThanComparable<Iter::value_type>
|
||||
// void
|
||||
// partial_sort(Iter first, Iter middle, Iter last);
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
void
|
||||
test_larger_sorts(unsigned N, unsigned M)
|
||||
{
|
||||
assert(N != 0);
|
||||
int* array = new int[N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
array[i] = i;
|
||||
std::random_shuffle(array, array+N);
|
||||
std::partial_sort(array, array+M, array+N);
|
||||
for (int i = 0; i < M; ++i)
|
||||
assert(array[i] == i);
|
||||
delete [] array;
|
||||
}
|
||||
|
||||
void
|
||||
test_larger_sorts(unsigned N)
|
||||
{
|
||||
test_larger_sorts(N, 0);
|
||||
test_larger_sorts(N, 1);
|
||||
test_larger_sorts(N, 2);
|
||||
test_larger_sorts(N, 3);
|
||||
test_larger_sorts(N, N/2-1);
|
||||
test_larger_sorts(N, N/2);
|
||||
test_larger_sorts(N, N/2+1);
|
||||
test_larger_sorts(N, N-2);
|
||||
test_larger_sorts(N, N-1);
|
||||
test_larger_sorts(N, N);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int i = 0;
|
||||
std::partial_sort(&i, &i, &i);
|
||||
assert(i == 0);
|
||||
test_larger_sorts(10);
|
||||
test_larger_sorts(256);
|
||||
test_larger_sorts(257);
|
||||
test_larger_sorts(499);
|
||||
test_larger_sorts(500);
|
||||
test_larger_sorts(997);
|
||||
test_larger_sorts(1000);
|
||||
test_larger_sorts(1009);
|
||||
}
|
@@ -0,0 +1,87 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <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<RandomAccessIterator Iter, StrictWeakOrder<auto, Iter::value_type> Compare>
|
||||
// requires ShuffleIterator<Iter>
|
||||
// && CopyConstructible<Compare>
|
||||
// void
|
||||
// partial_sort(Iter first, Iter middle, Iter last, Compare comp);
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
#ifdef _LIBCPP_MOVE
|
||||
#include <memory>
|
||||
|
||||
struct indirect_less
|
||||
{
|
||||
template <class P>
|
||||
bool operator()(const P& x, const P& y)
|
||||
{return *x < *y;}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
void
|
||||
test_larger_sorts(unsigned N, unsigned M)
|
||||
{
|
||||
assert(N != 0);
|
||||
int* array = new int[N];
|
||||
for (int i = 0; i < N; ++i)
|
||||
array[i] = i;
|
||||
std::random_shuffle(array, array+N);
|
||||
std::partial_sort(array, array+M, array+N, std::greater<int>());
|
||||
for (int i = 0; i < M; ++i)
|
||||
assert(array[i] == N-i-1);
|
||||
delete [] array;
|
||||
}
|
||||
|
||||
void
|
||||
test_larger_sorts(unsigned N)
|
||||
{
|
||||
test_larger_sorts(N, 0);
|
||||
test_larger_sorts(N, 1);
|
||||
test_larger_sorts(N, 2);
|
||||
test_larger_sorts(N, 3);
|
||||
test_larger_sorts(N, N/2-1);
|
||||
test_larger_sorts(N, N/2);
|
||||
test_larger_sorts(N, N/2+1);
|
||||
test_larger_sorts(N, N-2);
|
||||
test_larger_sorts(N, N-1);
|
||||
test_larger_sorts(N, N);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int i = 0;
|
||||
std::partial_sort(&i, &i, &i);
|
||||
assert(i == 0);
|
||||
test_larger_sorts(10);
|
||||
test_larger_sorts(256);
|
||||
test_larger_sorts(257);
|
||||
test_larger_sorts(499);
|
||||
test_larger_sorts(500);
|
||||
test_larger_sorts(997);
|
||||
test_larger_sorts(1000);
|
||||
test_larger_sorts(1009);
|
||||
|
||||
#ifdef _LIBCPP_MOVE
|
||||
{
|
||||
std::vector<std::unique_ptr<int> > v(1000);
|
||||
for (int i = 0; i < v.size(); ++i)
|
||||
v[i].reset(new int(i));
|
||||
std::partial_sort(v.begin(), v.begin() + v.size()/2, v.end(), indirect_less());
|
||||
for (int i = 0; i < v.size()/2; ++i)
|
||||
assert(*v[i] == i);
|
||||
}
|
||||
#endif
|
||||
}
|
150
test/algorithms/alg.sorting/alg.sort/sort/sort.pass.cpp
Normal file
150
test/algorithms/alg.sorting/alg.sort/sort/sort.pass.cpp
Normal file
@@ -0,0 +1,150 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <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<RandomAccessIterator Iter>
|
||||
// requires ShuffleIterator<Iter>
|
||||
// && LessThanComparable<Iter::value_type>
|
||||
// void
|
||||
// sort(Iter first, Iter last);
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
template <class RI>
|
||||
void
|
||||
test_sort_helper(RI f, RI l)
|
||||
{
|
||||
typedef typename std::iterator_traits<RI>::value_type value_type;
|
||||
if (f != l)
|
||||
{
|
||||
long len = l - f;
|
||||
value_type* save(new value_type[len]);
|
||||
do
|
||||
{
|
||||
std::copy(f, l, save);
|
||||
std::sort(save, save+len);
|
||||
assert(std::is_sorted(save, save+len));
|
||||
} while (std::next_permutation(f, l));
|
||||
delete [] save;
|
||||
}
|
||||
}
|
||||
|
||||
template <class RI>
|
||||
void
|
||||
test_sort_driver_driver(RI f, RI l, int start, RI real_last)
|
||||
{
|
||||
for (RI i = l; i > f + start;)
|
||||
{
|
||||
*--i = start;
|
||||
if (f == i)
|
||||
{
|
||||
test_sort_helper(f, real_last);
|
||||
}
|
||||
if (start > 0)
|
||||
test_sort_driver_driver(f, i, start-1, real_last);
|
||||
}
|
||||
}
|
||||
|
||||
template <class RI>
|
||||
void
|
||||
test_sort_driver(RI f, RI l, int start)
|
||||
{
|
||||
test_sort_driver_driver(f, l, start, l);
|
||||
}
|
||||
|
||||
template <unsigned sa>
|
||||
void
|
||||
test_sort_()
|
||||
{
|
||||
int ia[sa];
|
||||
for (int i = 0; i < sa; ++i)
|
||||
{
|
||||
test_sort_driver(ia, ia+sa, i);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
test_larger_sorts(unsigned N, unsigned M)
|
||||
{
|
||||
assert(N != 0);
|
||||
assert(M != 0);
|
||||
// create array length N filled with M different numbers
|
||||
int* array = new int[N];
|
||||
int x = 0;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
array[i] = x;
|
||||
if (++x == M)
|
||||
x = 0;
|
||||
}
|
||||
// test saw tooth pattern
|
||||
std::sort(array, array+N);
|
||||
assert(std::is_sorted(array, array+N));
|
||||
// test random pattern
|
||||
std::random_shuffle(array, array+N);
|
||||
std::sort(array, array+N);
|
||||
assert(std::is_sorted(array, array+N));
|
||||
// test sorted pattern
|
||||
std::sort(array, array+N);
|
||||
assert(std::is_sorted(array, array+N));
|
||||
// test reverse sorted pattern
|
||||
std::reverse(array, array+N);
|
||||
std::sort(array, array+N);
|
||||
assert(std::is_sorted(array, array+N));
|
||||
// test swap ranges 2 pattern
|
||||
std::swap_ranges(array, array+N/2, array+N/2);
|
||||
std::sort(array, array+N);
|
||||
assert(std::is_sorted(array, array+N));
|
||||
// test reverse swap ranges 2 pattern
|
||||
std::reverse(array, array+N);
|
||||
std::swap_ranges(array, array+N/2, array+N/2);
|
||||
std::sort(array, array+N);
|
||||
assert(std::is_sorted(array, array+N));
|
||||
delete [] array;
|
||||
}
|
||||
|
||||
void
|
||||
test_larger_sorts(unsigned N)
|
||||
{
|
||||
test_larger_sorts(N, 1);
|
||||
test_larger_sorts(N, 2);
|
||||
test_larger_sorts(N, 3);
|
||||
test_larger_sorts(N, N/2-1);
|
||||
test_larger_sorts(N, N/2);
|
||||
test_larger_sorts(N, N/2+1);
|
||||
test_larger_sorts(N, N-2);
|
||||
test_larger_sorts(N, N-1);
|
||||
test_larger_sorts(N, N);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// test null range
|
||||
int d = 0;
|
||||
std::sort(&d, &d);
|
||||
// exhaustively test all possibilities up to length 8
|
||||
test_sort_<1>();
|
||||
test_sort_<2>();
|
||||
test_sort_<3>();
|
||||
test_sort_<4>();
|
||||
test_sort_<5>();
|
||||
test_sort_<6>();
|
||||
test_sort_<7>();
|
||||
test_sort_<8>();
|
||||
|
||||
test_larger_sorts(256);
|
||||
test_larger_sorts(257);
|
||||
test_larger_sorts(499);
|
||||
test_larger_sorts(500);
|
||||
test_larger_sorts(997);
|
||||
test_larger_sorts(1000);
|
||||
test_larger_sorts(1009);
|
||||
}
|
58
test/algorithms/alg.sorting/alg.sort/sort/sort_comp.pass.cpp
Normal file
58
test/algorithms/alg.sorting/alg.sort/sort/sort_comp.pass.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <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<RandomAccessIterator Iter, StrictWeakOrder<auto, Iter::value_type> Compare>
|
||||
// requires ShuffleIterator<Iter>
|
||||
// && CopyConstructible<Compare>
|
||||
// void
|
||||
// sort(Iter first, Iter last, Compare comp);
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#ifdef _LIBCPP_MOVE
|
||||
#include <memory>
|
||||
|
||||
struct indirect_less
|
||||
{
|
||||
template <class P>
|
||||
bool operator()(const P& x, const P& y)
|
||||
{return *x < *y;}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::vector<int> v(1000);
|
||||
for (int i = 0; i < v.size(); ++i)
|
||||
v[i] = i;
|
||||
std::sort(v.begin(), v.end(), std::greater<int>());
|
||||
std::reverse(v.begin(), v.end());
|
||||
assert(std::is_sorted(v.begin(), v.end()));
|
||||
}
|
||||
|
||||
#ifdef _LIBCPP_MOVE
|
||||
{
|
||||
std::vector<std::unique_ptr<int> > v(1000);
|
||||
for (int i = 0; i < v.size(); ++i)
|
||||
v[i].reset(new int(i));
|
||||
std::sort(v.begin(), v.end(), indirect_less());
|
||||
assert(std::is_sorted(v.begin(), v.end(), indirect_less()));
|
||||
assert(*v[0] == 0);
|
||||
assert(*v[1] == 1);
|
||||
assert(*v[2] == 2);
|
||||
}
|
||||
#endif
|
||||
}
|
@@ -0,0 +1,150 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <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<RandomAccessIterator Iter>
|
||||
// requires ShuffleIterator<Iter>
|
||||
// && LessThanComparable<Iter::value_type>
|
||||
// void
|
||||
// stable_sort(Iter first, Iter last);
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
template <class RI>
|
||||
void
|
||||
test_sort_helper(RI f, RI l)
|
||||
{
|
||||
typedef typename std::iterator_traits<RI>::value_type value_type;
|
||||
if (f != l)
|
||||
{
|
||||
long len = l - f;
|
||||
value_type* save(new value_type[len]);
|
||||
do
|
||||
{
|
||||
std::copy(f, l, save);
|
||||
std::stable_sort(save, save+len);
|
||||
assert(std::is_sorted(save, save+len));
|
||||
} while (std::next_permutation(f, l));
|
||||
delete [] save;
|
||||
}
|
||||
}
|
||||
|
||||
template <class RI>
|
||||
void
|
||||
test_sort_driver_driver(RI f, RI l, int start, RI real_last)
|
||||
{
|
||||
for (RI i = l; i > f + start;)
|
||||
{
|
||||
*--i = start;
|
||||
if (f == i)
|
||||
{
|
||||
test_sort_helper(f, real_last);
|
||||
}
|
||||
if (start > 0)
|
||||
test_sort_driver_driver(f, i, start-1, real_last);
|
||||
}
|
||||
}
|
||||
|
||||
template <class RI>
|
||||
void
|
||||
test_sort_driver(RI f, RI l, int start)
|
||||
{
|
||||
test_sort_driver_driver(f, l, start, l);
|
||||
}
|
||||
|
||||
template <unsigned sa>
|
||||
void
|
||||
test_sort_()
|
||||
{
|
||||
int ia[sa];
|
||||
for (int i = 0; i < sa; ++i)
|
||||
{
|
||||
test_sort_driver(ia, ia+sa, i);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
test_larger_sorts(unsigned N, unsigned M)
|
||||
{
|
||||
assert(N != 0);
|
||||
assert(M != 0);
|
||||
// create array length N filled with M different numbers
|
||||
int* array = new int[N];
|
||||
int x = 0;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
array[i] = x;
|
||||
if (++x == M)
|
||||
x = 0;
|
||||
}
|
||||
// test saw tooth pattern
|
||||
std::stable_sort(array, array+N);
|
||||
assert(std::is_sorted(array, array+N));
|
||||
// test random pattern
|
||||
std::random_shuffle(array, array+N);
|
||||
std::stable_sort(array, array+N);
|
||||
assert(std::is_sorted(array, array+N));
|
||||
// test sorted pattern
|
||||
std::stable_sort(array, array+N);
|
||||
assert(std::is_sorted(array, array+N));
|
||||
// test reverse sorted pattern
|
||||
std::reverse(array, array+N);
|
||||
std::stable_sort(array, array+N);
|
||||
assert(std::is_sorted(array, array+N));
|
||||
// test swap ranges 2 pattern
|
||||
std::swap_ranges(array, array+N/2, array+N/2);
|
||||
std::stable_sort(array, array+N);
|
||||
assert(std::is_sorted(array, array+N));
|
||||
// test reverse swap ranges 2 pattern
|
||||
std::reverse(array, array+N);
|
||||
std::swap_ranges(array, array+N/2, array+N/2);
|
||||
std::stable_sort(array, array+N);
|
||||
assert(std::is_sorted(array, array+N));
|
||||
delete [] array;
|
||||
}
|
||||
|
||||
void
|
||||
test_larger_sorts(unsigned N)
|
||||
{
|
||||
test_larger_sorts(N, 1);
|
||||
test_larger_sorts(N, 2);
|
||||
test_larger_sorts(N, 3);
|
||||
test_larger_sorts(N, N/2-1);
|
||||
test_larger_sorts(N, N/2);
|
||||
test_larger_sorts(N, N/2+1);
|
||||
test_larger_sorts(N, N-2);
|
||||
test_larger_sorts(N, N-1);
|
||||
test_larger_sorts(N, N);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// test null range
|
||||
int d = 0;
|
||||
std::stable_sort(&d, &d);
|
||||
// exhaustively test all possibilities up to length 8
|
||||
test_sort_<1>();
|
||||
test_sort_<2>();
|
||||
test_sort_<3>();
|
||||
test_sort_<4>();
|
||||
test_sort_<5>();
|
||||
test_sort_<6>();
|
||||
test_sort_<7>();
|
||||
test_sort_<8>();
|
||||
|
||||
test_larger_sorts(256);
|
||||
test_larger_sorts(257);
|
||||
test_larger_sorts(499);
|
||||
test_larger_sorts(500);
|
||||
test_larger_sorts(997);
|
||||
test_larger_sorts(1000);
|
||||
test_larger_sorts(1009);
|
||||
}
|
@@ -0,0 +1,83 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <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<RandomAccessIterator Iter, StrictWeakOrder<auto, Iter::value_type> Compare>
|
||||
// requires ShuffleIterator<Iter>
|
||||
// && CopyConstructible<Compare>
|
||||
// void
|
||||
// stable_sort(Iter first, Iter last, Compare comp);
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#ifdef _LIBCPP_MOVE
|
||||
#include <memory>
|
||||
|
||||
struct indirect_less
|
||||
{
|
||||
template <class P>
|
||||
bool operator()(const P& x, const P& y)
|
||||
{return *x < *y;}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
struct first_only
|
||||
{
|
||||
bool operator()(const std::pair<int, int>& x, const std::pair<int, int>& y)
|
||||
{
|
||||
return x.first < y.first;
|
||||
}
|
||||
};
|
||||
|
||||
void test()
|
||||
{
|
||||
typedef std::pair<int, int> P;
|
||||
const int N = 1000;
|
||||
const int M = 10;
|
||||
std::vector<P> v(N);
|
||||
int x = 0;
|
||||
int ver = 0;
|
||||
for (int i = 0; i < N; ++i)
|
||||
{
|
||||
v[i] = P(x, ver);
|
||||
if (++x == M)
|
||||
{
|
||||
x = 0;
|
||||
++ver;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < N - M; i += M)
|
||||
{
|
||||
std::random_shuffle(v.begin() + i, v.begin() + i + M);
|
||||
}
|
||||
std::stable_sort(v.begin(), v.end(), first_only());
|
||||
assert(std::is_sorted(v.begin(), v.end()));
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test();
|
||||
|
||||
#ifdef _LIBCPP_MOVE
|
||||
{
|
||||
std::vector<std::unique_ptr<int> > v(1000);
|
||||
for (int i = 0; i < v.size(); ++i)
|
||||
v[i].reset(new int(i));
|
||||
std::stable_sort(v.begin(), v.end(), indirect_less());
|
||||
assert(std::is_sorted(v.begin(), v.end(), indirect_less()));
|
||||
assert(*v[0] == 0);
|
||||
assert(*v[1] == 1);
|
||||
assert(*v[2] == 2);
|
||||
}
|
||||
#endif
|
||||
}
|
Reference in New Issue
Block a user