upper_bound.pass.cpp revision 8226d0b7c5f9e3a4d4a2b94179234085d973841f
1a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville//===----------------------------------------------------------------------===// 2a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville// 3a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville// The LLVM Compiler Infrastructure 4a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville// 5a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville// This file is dual licensed under the MIT and the University of Illinois Open 6a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville// Source Licenses. See LICENSE.TXT for details. 7a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville// 8a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville//===----------------------------------------------------------------------===// 9a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville 10a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville// <algorithm> 11a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville 12a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville// template<ForwardIterator Iter, class T> 13a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville// requires HasLess<T, Iter::value_type> 14a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville// Iter 15a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville// upper_bound(Iter first, Iter last, const T& value); 16a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville 17a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville#include <algorithm> 18a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville#include <vector> 19a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville#include <cassert> 20a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville 21f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan#include "../../../../iterators.h" 22a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville 23f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajantemplate <class Iter, class T> 24b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wenvoid 25f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajantest(Iter first, Iter last, const T& value) 26b29851580bba4a13ddbf7a534d8b09295eb2c60fYe Wen{ 27a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville Iter i = std::upper_bound(first, last, value); 28a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville for (Iter j = first; j != i; ++j) 29f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan assert(!(value < *j)); 30fa8a17ed53a72fbc4fb22cc41a7abb088b2cb788Wink Saville for (Iter j = i; j != last; ++j) 31f6c0e3489a9365a4851bf3ed19dab18773ecbf65Amit Mahajan assert(value < *j); 32a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville} 33a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville 34a8467dd0c524787104b1ccdddc5e8af10ba729edWink Savilletemplate <class Iter> 35a8467dd0c524787104b1ccdddc5e8af10ba729edWink Savillevoid 36a8467dd0c524787104b1ccdddc5e8af10ba729edWink Savilletest() 37a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville{ 38a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville const unsigned N = 1000; 39a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville const unsigned M = 10; 40a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville std::vector<int> v(N); 41a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville int x = 0; 42a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville for (int i = 0; i < v.size(); ++i) 43a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville { 44a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville v[i] = x; 45a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville if (++x == M) 46a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville x = 0; 47a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville } 48a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville std::sort(v.begin(), v.end()); 49a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville for (x = 0; x <= M; ++x) 50a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville test(Iter(v.data()), Iter(v.data()+v.size()), x); 51a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville} 52a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville 53a8467dd0c524787104b1ccdddc5e8af10ba729edWink Savilleint main() 54a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville{ 556a5ef38e6ae3d3a3ad90ae180388fe85de0495a2Wink Saville int d[] = {0, 1, 2, 3}; 56a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville for (int* e = d; e <= d+4; ++e) 57a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville for (int x = -1; x <= 4; ++x) 58a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville test(d, e, x); 59a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville 60b237a11044ed842d2865ff8c8716befb06b6ca25Wink Saville test<forward_iterator<const int*> >(); 61a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville test<bidirectional_iterator<const int*> >(); 62a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville test<random_access_iterator<const int*> >(); 63a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville test<const int*>(); 64a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville} 65a8467dd0c524787104b1ccdddc5e8af10ba729edWink Saville