Commit d6d4b339 by Patrick Palka

libstdc++: Add a move-only testsuite iterator type

This adds a move-only testsuite iterator wrapper to <testsuite_iterators.h>
which will be used in the tests for LWG 3355.  The tests for LWG 3389 and 3390
are adjusted to use this new iterator wrapper.

libstdc++-v3/ChangeLog:

	* testsuite/util/testsuite_iterators.h (input_iterator_wrapper_nocopy):
	New testsuite iterator.
	* testsuite/24_iterators/counted_iterator/lwg3389.cc: Use it.
	* testsuite/24_iterators/move_iterator/lwg3390.cc: Likewise.
parent 05779e2c
2020-03-04 Patrick Palka <ppalka@redhat.com> 2020-03-04 Patrick Palka <ppalka@redhat.com>
* testsuite/util/testsuite_iterators.h (input_iterator_wrapper_nocopy):
New testsuite iterator.
* testsuite/24_iterators/counted_iterator/lwg3389.cc: use it.
* testsuite/24_iterators/move_iterator/lwg3390.cc: Likewise.
* include/bits/ranges_uninitialized.h * include/bits/ranges_uninitialized.h
(uninitialized_copy_fn::operator()): Pass a reference type as the first (uninitialized_copy_fn::operator()): Pass a reference type as the first
argument to is_nothrow_assignable_v. argument to is_nothrow_assignable_v.
......
...@@ -23,44 +23,13 @@ ...@@ -23,44 +23,13 @@
#include <testsuite_iterators.h> #include <testsuite_iterators.h>
using __gnu_test::test_range; using __gnu_test::test_range;
using __gnu_test::input_iterator_wrapper; using __gnu_test::input_iterator_wrapper_nocopy;
template<typename T>
struct move_only_wrapper : input_iterator_wrapper<T>
{
using input_iterator_wrapper<T>::input_iterator_wrapper;
move_only_wrapper()
: input_iterator_wrapper<T>(nullptr, nullptr)
{ }
move_only_wrapper(const move_only_wrapper&) = delete;
move_only_wrapper&
operator=(const move_only_wrapper&) = delete;
move_only_wrapper(move_only_wrapper&&) = default;
move_only_wrapper&
operator=(move_only_wrapper&&) = default;
using input_iterator_wrapper<T>::operator++;
move_only_wrapper&
operator++()
{
input_iterator_wrapper<T>::operator++();
return *this;
}
};
static_assert(std::input_iterator<move_only_wrapper<int>>);
static_assert(!std::forward_iterator<move_only_wrapper<int>>);
static_assert(!std::copyable<move_only_wrapper<int>>);
// LWG 3389 // LWG 3389
void void
test01() test01()
{ {
int x[] = {1,2,3,4}; int x[] = {1,2,3,4};
test_range<int, move_only_wrapper> rx(x); test_range<int, input_iterator_wrapper_nocopy> rx(x);
auto it = std::counted_iterator(rx.begin(), 2); auto it = std::counted_iterator(rx.begin(), 2);
} }
...@@ -23,44 +23,13 @@ ...@@ -23,44 +23,13 @@
#include <testsuite_iterators.h> #include <testsuite_iterators.h>
using __gnu_test::test_range; using __gnu_test::test_range;
using __gnu_test::input_iterator_wrapper; using __gnu_test::input_iterator_wrapper_nocopy;
template<typename T>
struct move_only_wrapper : input_iterator_wrapper<T>
{
using input_iterator_wrapper<T>::input_iterator_wrapper;
move_only_wrapper()
: input_iterator_wrapper<T>(nullptr, nullptr)
{ }
move_only_wrapper(const move_only_wrapper&) = delete;
move_only_wrapper&
operator=(const move_only_wrapper&) = delete;
move_only_wrapper(move_only_wrapper&&) = default;
move_only_wrapper&
operator=(move_only_wrapper&&) = default;
using input_iterator_wrapper<T>::operator++;
move_only_wrapper&
operator++()
{
input_iterator_wrapper<T>::operator++();
return *this;
}
};
static_assert(std::input_iterator<move_only_wrapper<int>>);
static_assert(!std::forward_iterator<move_only_wrapper<int>>);
static_assert(!std::copyable<move_only_wrapper<int>>);
// LWG 3390 // LWG 3390
void void
test01() test01()
{ {
int x[] = {1,2,3,4}; int x[] = {1,2,3,4};
test_range<int, move_only_wrapper> rx(x); test_range<int, input_iterator_wrapper_nocopy> rx(x);
auto it = std::make_move_iterator(rx.begin()); auto it = std::make_move_iterator(rx.begin());
} }
...@@ -674,6 +674,34 @@ namespace __gnu_test ...@@ -674,6 +674,34 @@ namespace __gnu_test
{ return iter -= n; } { return iter -= n; }
}; };
// A move-only input iterator type.
template<typename T>
struct input_iterator_wrapper_nocopy : input_iterator_wrapper<T>
{
using input_iterator_wrapper<T>::input_iterator_wrapper;
input_iterator_wrapper_nocopy()
: input_iterator_wrapper<T>(nullptr, nullptr)
{ }
input_iterator_wrapper_nocopy(const input_iterator_wrapper_nocopy&) = delete;
input_iterator_wrapper_nocopy&
operator=(const input_iterator_wrapper_nocopy&) = delete;
input_iterator_wrapper_nocopy(input_iterator_wrapper_nocopy&&) = default;
input_iterator_wrapper_nocopy&
operator=(input_iterator_wrapper_nocopy&&) = default;
using input_iterator_wrapper<T>::operator++;
input_iterator_wrapper_nocopy&
operator++()
{
input_iterator_wrapper<T>::operator++();
return *this;
}
};
// A type meeting the minimum std::range requirements // A type meeting the minimum std::range requirements
template<typename T, template<typename> class Iter> template<typename T, template<typename> class Iter>
class test_range class test_range
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment