brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.7 KiB · 704cfff Raw
183 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// <map>10 11// class multimap12 13//       iterator lower_bound(const key_type& k);14// const_iterator lower_bound(const key_type& k) const;15 16#include <map>17#include <cassert>18 19#include "test_macros.h"20#include "min_allocator.h"21#include "private_constructor.h"22#include "is_transparent.h"23 24int main(int, char**) {25  typedef std::pair<const int, double> V;26  {27    typedef std::multimap<int, double> M;28    {29      typedef M::iterator R;30      V ar[] = {V(5, 1), V(5, 2), V(5, 3), V(7, 1), V(7, 2), V(7, 3), V(9, 1), V(9, 2), V(9, 3)};31      M m(ar, ar + sizeof(ar) / sizeof(ar[0]));32      R r = m.lower_bound(4);33      assert(r == m.begin());34      r = m.lower_bound(5);35      assert(r == m.begin());36      r = m.lower_bound(6);37      assert(r == std::next(m.begin(), 3));38      r = m.lower_bound(7);39      assert(r == std::next(m.begin(), 3));40      r = m.lower_bound(8);41      assert(r == std::next(m.begin(), 6));42      r = m.lower_bound(9);43      assert(r == std::next(m.begin(), 6));44      r = m.lower_bound(10);45      assert(r == m.end());46    }47    {48      typedef M::const_iterator R;49      V ar[] = {V(5, 1), V(5, 2), V(5, 3), V(7, 1), V(7, 2), V(7, 3), V(9, 1), V(9, 2), V(9, 3)};50      const M m(ar, ar + sizeof(ar) / sizeof(ar[0]));51      R r = m.lower_bound(4);52      assert(r == m.begin());53      r = m.lower_bound(5);54      assert(r == m.begin());55      r = m.lower_bound(6);56      assert(r == std::next(m.begin(), 3));57      r = m.lower_bound(7);58      assert(r == std::next(m.begin(), 3));59      r = m.lower_bound(8);60      assert(r == std::next(m.begin(), 6));61      r = m.lower_bound(9);62      assert(r == std::next(m.begin(), 6));63      r = m.lower_bound(10);64      assert(r == m.end());65    }66  }67#if TEST_STD_VER >= 1168  {69    typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;70    {71      typedef M::iterator R;72      V ar[] = {V(5, 1), V(5, 2), V(5, 3), V(7, 1), V(7, 2), V(7, 3), V(9, 1), V(9, 2), V(9, 3)};73      M m(ar, ar + sizeof(ar) / sizeof(ar[0]));74      R r = m.lower_bound(4);75      assert(r == m.begin());76      r = m.lower_bound(5);77      assert(r == m.begin());78      r = m.lower_bound(6);79      assert(r == std::next(m.begin(), 3));80      r = m.lower_bound(7);81      assert(r == std::next(m.begin(), 3));82      r = m.lower_bound(8);83      assert(r == std::next(m.begin(), 6));84      r = m.lower_bound(9);85      assert(r == std::next(m.begin(), 6));86      r = m.lower_bound(10);87      assert(r == m.end());88    }89    {90      typedef M::const_iterator R;91      V ar[] = {V(5, 1), V(5, 2), V(5, 3), V(7, 1), V(7, 2), V(7, 3), V(9, 1), V(9, 2), V(9, 3)};92      const M m(ar, ar + sizeof(ar) / sizeof(ar[0]));93      R r = m.lower_bound(4);94      assert(r == m.begin());95      r = m.lower_bound(5);96      assert(r == m.begin());97      r = m.lower_bound(6);98      assert(r == std::next(m.begin(), 3));99      r = m.lower_bound(7);100      assert(r == std::next(m.begin(), 3));101      r = m.lower_bound(8);102      assert(r == std::next(m.begin(), 6));103      r = m.lower_bound(9);104      assert(r == std::next(m.begin(), 6));105      r = m.lower_bound(10);106      assert(r == m.end());107    }108  }109#endif110#if TEST_STD_VER > 11111  {112    typedef std::multimap<int, double, std::less<>> M;113    typedef M::iterator R;114    V ar[] = {V(5, 1), V(5, 2), V(5, 3), V(7, 1), V(7, 2), V(7, 3), V(9, 1), V(9, 2), V(9, 3)};115    M m(ar, ar + sizeof(ar) / sizeof(ar[0]));116    R r = m.lower_bound(4);117    assert(r == m.begin());118    r = m.lower_bound(5);119    assert(r == m.begin());120    r = m.lower_bound(6);121    assert(r == std::next(m.begin(), 3));122    r = m.lower_bound(7);123    assert(r == std::next(m.begin(), 3));124    r = m.lower_bound(8);125    assert(r == std::next(m.begin(), 6));126    r = m.lower_bound(9);127    assert(r == std::next(m.begin(), 6));128    r = m.lower_bound(10);129    assert(r == m.end());130 131    r = m.lower_bound(C2Int(4));132    assert(r == m.begin());133    r = m.lower_bound(C2Int(5));134    assert(r == m.begin());135    r = m.lower_bound(C2Int(6));136    assert(r == std::next(m.begin(), 3));137    r = m.lower_bound(C2Int(7));138    assert(r == std::next(m.begin(), 3));139    r = m.lower_bound(C2Int(8));140    assert(r == std::next(m.begin(), 6));141    r = m.lower_bound(C2Int(9));142    assert(r == std::next(m.begin(), 6));143    r = m.lower_bound(C2Int(10));144    assert(r == m.end());145  }146 147  {148    typedef PrivateConstructor PC;149    typedef std::multimap<PC, double, std::less<>> M;150    typedef M::iterator R;151 152    M m;153    m.insert(std::make_pair<PC, double>(PC::make(5), 1));154    m.insert(std::make_pair<PC, double>(PC::make(5), 2));155    m.insert(std::make_pair<PC, double>(PC::make(5), 3));156    m.insert(std::make_pair<PC, double>(PC::make(7), 1));157    m.insert(std::make_pair<PC, double>(PC::make(7), 2));158    m.insert(std::make_pair<PC, double>(PC::make(7), 3));159    m.insert(std::make_pair<PC, double>(PC::make(9), 1));160    m.insert(std::make_pair<PC, double>(PC::make(9), 2));161    m.insert(std::make_pair<PC, double>(PC::make(9), 3));162 163    R r = m.lower_bound(4);164    assert(r == m.begin());165    r = m.lower_bound(5);166    assert(r == m.begin());167    r = m.lower_bound(6);168    assert(r == std::next(m.begin(), 3));169    r = m.lower_bound(7);170    assert(r == std::next(m.begin(), 3));171    r = m.lower_bound(8);172    assert(r == std::next(m.begin(), 6));173    r = m.lower_bound(9);174    assert(r == std::next(m.begin(), 6));175    r = m.lower_bound(10);176    assert(r == m.end());177  }178 179#endif180 181  return 0;182}183