brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.5 KiB · ebacec5 Raw
96 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// <algorithm>10 11// template<ForwardIterator Iter, class T>12//   requires OutputIterator<Iter, RvalueOf<Iter::reference>::type>13//         && HasEqualTo<Iter::value_type, T>14//   constexpr Iter         // constexpr after C++1715//   remove(Iter first, Iter last, const T& value);16 17#include <algorithm>18#include <cassert>19#include <memory>20 21#include "test_macros.h"22#include "test_iterators.h"23 24#if TEST_STD_VER > 1725TEST_CONSTEXPR bool test_constexpr() {26    int ia[] = {1, 3, 5, 2, 5, 6};27 28    auto it = std::remove(std::begin(ia), std::end(ia), 5);29 30    return (std::begin(ia) + std::size(ia) - 2) == it  // we removed two elements31        && std::none_of(std::begin(ia), it, [](int a) {return a == 5; })32           ;33    }34#endif35 36template <class Iter>37void38test()39{40    int ia[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};41    const unsigned sa = sizeof(ia)/sizeof(ia[0]);42    Iter r = std::remove(Iter(ia), Iter(ia+sa), 2);43    assert(base(r) == ia + sa-3);44    assert(ia[0] == 0);45    assert(ia[1] == 1);46    assert(ia[2] == 3);47    assert(ia[3] == 4);48    assert(ia[4] == 3);49    assert(ia[5] == 4);50}51 52#if TEST_STD_VER >= 1153template <class Iter>54void55test1()56{57    const unsigned sa = 9;58    std::unique_ptr<int> ia[sa];59    ia[0].reset(new int(0));60    ia[1].reset(new int(1));61    ia[3].reset(new int(3));62    ia[4].reset(new int(4));63    ia[6].reset(new int(3));64    ia[7].reset(new int(4));65    Iter r = std::remove(Iter(ia), Iter(ia+sa), std::unique_ptr<int>());66    assert(base(r) == ia + sa-3);67    assert(*ia[0] == 0);68    assert(*ia[1] == 1);69    assert(*ia[2] == 3);70    assert(*ia[3] == 4);71    assert(*ia[4] == 3);72    assert(*ia[5] == 4);73}74#endif // TEST_STD_VER >= 1175 76int main(int, char**)77{78    test<forward_iterator<int*> >();79    test<bidirectional_iterator<int*> >();80    test<random_access_iterator<int*> >();81    test<int*>();82 83#if TEST_STD_VER >= 1184    test1<forward_iterator<std::unique_ptr<int>*> >();85    test1<bidirectional_iterator<std::unique_ptr<int>*> >();86    test1<random_access_iterator<std::unique_ptr<int>*> >();87    test1<std::unique_ptr<int>*>();88#endif // TEST_STD_VER >= 1189 90#if TEST_STD_VER > 1791    static_assert(test_constexpr());92#endif93 94  return 0;95}96