[libc++] [test] Constexpr-ify a couple of insert-iterator tests.

This should have been done in D96385; thanks ldionne for the catch!
Also, make the back/front inserter behavior tests a little more thorough,
which incidentally caught a cut-and-paste-bug in `nasty_list`, so fix that.

Differential Revision: https://reviews.llvm.org/D103318
This commit is contained in:
Arthur O'Dwyer 2021-05-28 09:46:01 -04:00
parent b6afdbac13
commit 8a5f0d8838
6 changed files with 44 additions and 24 deletions

View File

@ -10,25 +10,30 @@
// back_insert_iterator
// explicit back_insert_iterator(Cont& x);
// explicit back_insert_iterator(Cont& x); // constexpr in C++20
#include <iterator>
#include <vector>
#include "nasty_containers.h"
#include "test_macros.h"
#include "nasty_containers.h"
#include "test_constexpr_container.h"
template <class C>
void
TEST_CONSTEXPR_CXX20 bool
test(C c)
{
std::back_insert_iterator<C> i(c);
return true;
}
int main(int, char**)
{
test(std::vector<int>());
test(nasty_vector<int>());
return 0;
#if TEST_STD_VER >= 20
test(ConstexprFixedCapacityDeque<int, 10>());
static_assert(test(ConstexprFixedCapacityDeque<int, 10>()));
#endif
return 0;
}

View File

@ -10,29 +10,41 @@
// template <BackInsertionContainer Cont>
// back_insert_iterator<Cont>
// back_inserter(Cont& x);
// back_inserter(Cont& x); // constexpr in C++20
// template <BackInsertionContainer Cont>
// front_insert_iterator<Cont>
// front_inserter(Cont& x); // constexpr in C++20
#include <iterator>
#include <vector>
#include <cassert>
#include "nasty_containers.h"
#include <iterator>
#include <list>
#include "test_macros.h"
#include "nasty_containers.h"
#include "test_constexpr_container.h"
template <class C>
void
TEST_CONSTEXPR_CXX20 bool
test(C c)
{
std::back_insert_iterator<C> i = std::back_inserter(c);
i = 0;
i = 3;
assert(c.size() == 1);
assert(c.back() == 0);
assert(c.back() == 3);
i = 4;
assert(c.size() == 2);
assert(c.back() == 4);
return true;
}
int main(int, char**)
{
test(std::vector<int>());
test(nasty_vector<int>());
return 0;
#if TEST_STD_VER >= 20
test(ConstexprFixedCapacityDeque<int, 10>());
static_assert(test(ConstexprFixedCapacityDeque<int, 10>()));
#endif
return 0;
}

View File

@ -10,7 +10,7 @@
// front_insert_iterator
// explicit front_insert_iterator(Cont& x);
// explicit front_insert_iterator(Cont& x); // constexpr in C++20
#include <iterator>
#include <list>

View File

@ -8,9 +8,9 @@
// <iterator>
// template <BackInsertionContainer Cont>
// template <FrontInsertionContainer Cont>
// front_insert_iterator<Cont>
// front_inserter(Cont& x);
// front_inserter(Cont& x); // constexpr in C++20
#include <cassert>
#include <iterator>
@ -25,9 +25,12 @@ TEST_CONSTEXPR_CXX20 bool
test(C c)
{
std::front_insert_iterator<C> i = std::front_inserter(c);
i = 0;
i = 3;
assert(c.size() == 1);
assert(c.front() == 0);
assert(c.front() == 3);
i = 4;
assert(c.size() == 2);
assert(c.front() == 4);
return true;
}

View File

@ -10,7 +10,7 @@
// insert_iterator
// insert_iterator(Cont& x, Cont::iterator i);
// insert_iterator(Cont& x, Cont::iterator i); // constexpr in C++20
#include <iterator>
#include <vector>

View File

@ -206,7 +206,7 @@ public:
void push_back(const value_type& x) { l_.push_back(x); }
#if TEST_STD_VER >= 11
void push_back(value_type&& x) { l_.push_back(std::forward<value_type&&>(x)); }
void push_front(value_type&& x) { l_.push_back(std::forward<value_type&&>(x)); }
void push_front(value_type&& x) { l_.push_front(std::forward<value_type&&>(x)); }
template <class... Args>
void emplace_back(Args&&... args) { l_.emplace_back(std::forward<Args>(args)...); }
template <class... Args>
@ -234,10 +234,10 @@ public:
#endif
iterator erase(const_iterator pos) { return l_.erase(pos); }
iterator erase(const_iterator pos, const_iterator last) { return l_.erase(pos, last); }
iterator erase(const_iterator first, const_iterator last) { return l_.erase(first, last); }
void resize(size_type) { l_.resize(); }
void resize(size_type, const value_type& c) { l_.resize(c); }
void resize(size_type n) { l_.resize(n); }
void resize(size_type n, const value_type& c) { l_.resize(n, c); }
void swap(nasty_list &nl)
#if TEST_STD_VER > 14