Commit 9921ac3d by Jonathan Wakely Committed by Jonathan Wakely

Minor improvements to testsuite iterator utilities

	* testsuite/util/testsuite_iterators.h (BoundsContainer::size()): Add
	new member function.
	(WritableObject::operator=): Constrain with enable_if when available.
	(remove_cv): Use std::remove_if when available.
	(test_container::it(int)): Use size().
	(test_container::size()): Use BoundsContainer::size().

From-SVN: r277578
parent 0ed4d408
2019-10-29 Jonathan Wakely <jwakely@redhat.com> 2019-10-29 Jonathan Wakely <jwakely@redhat.com>
* testsuite/util/testsuite_iterators.h (BoundsContainer::size()): Add
new member function.
(WritableObject::operator=): Constrain with enable_if when available.
(remove_cv): Use std::remove_if when available.
(test_container::it(int)): Use size().
(test_container::size()): Use BoundsContainer::size().
PR libstdc++/92267 PR libstdc++/92267
* include/bits/stl_deque.h (_Deque_iterator(const _Deque_iterator&)): * include/bits/stl_deque.h (_Deque_iterator(const _Deque_iterator&)):
Do not define as defaulted. Do not define as defaulted.
......
...@@ -56,8 +56,11 @@ namespace __gnu_test ...@@ -56,8 +56,11 @@ namespace __gnu_test
{ {
T* first; T* first;
T* last; T* last;
BoundsContainer(T* _first, T* _last) : first(_first), last(_last) BoundsContainer(T* _first, T* _last) : first(_first), last(_last)
{ } { }
std::size_t size() const { return last - first; }
}; };
// Simple container for holding state of a set of output iterators. // Simple container for holding state of a set of output iterators.
...@@ -66,13 +69,11 @@ namespace __gnu_test ...@@ -66,13 +69,11 @@ namespace __gnu_test
{ {
T* incrementedto; T* incrementedto;
bool* writtento; bool* writtento;
OutputContainer(T* _first, T* _last) OutputContainer(T* _first, T* _last)
: BoundsContainer<T>(_first, _last), incrementedto(_first) : BoundsContainer<T>(_first, _last), incrementedto(_first),
{ writtento(new bool[this->size()]())
writtento = new bool[this->last - this->first]; { }
for(int i = 0; i < this->last - this->first; i++)
writtento[i] = false;
}
~OutputContainer() ~OutputContainer()
{ delete[] writtento; } { delete[] writtento; }
...@@ -86,13 +87,14 @@ namespace __gnu_test ...@@ -86,13 +87,14 @@ namespace __gnu_test
public: public:
OutputContainer<T>* SharedInfo; OutputContainer<T>* SharedInfo;
WritableObject(T* ptr_in,OutputContainer<T>* SharedInfo_in):
WritableObject(T* ptr_in, OutputContainer<T>* SharedInfo_in):
ptr(ptr_in), SharedInfo(SharedInfo_in) ptr(ptr_in), SharedInfo(SharedInfo_in)
{ } { }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
template<class U> template<class U>
void typename std::enable_if<std::is_assignable<T&, U>::value>::type
operator=(U&& new_val) operator=(U&& new_val)
{ {
ITERATOR_VERIFY(SharedInfo->writtento[ptr - SharedInfo->first] == 0); ITERATOR_VERIFY(SharedInfo->writtento[ptr - SharedInfo->first] == 0);
...@@ -182,10 +184,14 @@ namespace __gnu_test ...@@ -182,10 +184,14 @@ namespace __gnu_test
void operator,(const T&, const output_iterator_wrapper<U>&) = delete; void operator,(const T&, const output_iterator_wrapper<U>&) = delete;
#endif #endif
#if __cplusplus >= 2011L
using std::remove_cv;
#else
template<typename T> struct remove_cv { typedef T type; }; template<typename T> struct remove_cv { typedef T type; };
template<typename T> struct remove_cv<const T> { typedef T type; }; template<typename T> struct remove_cv<const T> { typedef T type; };
template<typename T> struct remove_cv<volatile T> { typedef T type; }; template<typename T> struct remove_cv<volatile T> { typedef T type; };
template<typename T> struct remove_cv<const volatile T> { typedef T type; }; template<typename T> struct remove_cv<const volatile T> { typedef T type; };
#endif
/** /**
* @brief input_iterator wrapper for pointer * @brief input_iterator wrapper for pointer
...@@ -543,6 +549,7 @@ namespace __gnu_test ...@@ -543,6 +549,7 @@ namespace __gnu_test
struct test_container struct test_container
{ {
typename ItType<T>::ContainerType bounds; typename ItType<T>::ContainerType bounds;
test_container(T* _first, T* _last) : bounds(_first, _last) test_container(T* _first, T* _last) : bounds(_first, _last)
{ } { }
...@@ -556,7 +563,7 @@ namespace __gnu_test ...@@ -556,7 +563,7 @@ namespace __gnu_test
ItType<T> ItType<T>
it(int pos) it(int pos)
{ {
ITERATOR_VERIFY(pos >= 0 && pos <= (bounds.last - bounds.first)); ITERATOR_VERIFY(pos >= 0 && pos <= size());
return ItType<T>(bounds.first + pos, &bounds); return ItType<T>(bounds.first + pos, &bounds);
} }
...@@ -581,7 +588,7 @@ namespace __gnu_test ...@@ -581,7 +588,7 @@ namespace __gnu_test
std::size_t std::size_t
size() const size() const
{ return bounds.last - bounds.first; } { return bounds.size(); }
}; };
} }
#endif #endif
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