public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Minor improvements to testsuite iterator utilities
@ 2019-10-29 17:15 Jonathan Wakely
  2019-10-30 14:34 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Wakely @ 2019-10-29 17:15 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 368 bytes --]

	* 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().

Tested powerpc64le-linux, committed to trunk.



[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 3596 bytes --]

commit 8b8165ec804d990065bcf2ce4ef2a64926cc68c8
Author: redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Tue Oct 29 17:15:04 2019 +0000

    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().
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@277578 138bc75d-0d04-0410-961f-82ee72b054a4

diff --git a/libstdc++-v3/testsuite/util/testsuite_iterators.h b/libstdc++-v3/testsuite/util/testsuite_iterators.h
index d9a35622fb7..974490b1b6c 100644
--- a/libstdc++-v3/testsuite/util/testsuite_iterators.h
+++ b/libstdc++-v3/testsuite/util/testsuite_iterators.h
@@ -56,8 +56,11 @@ namespace __gnu_test
     {
       T* first;
       T* 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.
@@ -66,13 +69,11 @@ namespace __gnu_test
     {
       T* incrementedto;
       bool* writtento;
+
       OutputContainer(T* _first, T* _last)
-      : BoundsContainer<T>(_first, _last), incrementedto(_first)
-      {
-	writtento = new bool[this->last - this->first];
-	for(int i = 0; i < this->last - this->first; i++)
-	  writtento[i] = false;
-      }
+      : BoundsContainer<T>(_first, _last), incrementedto(_first),
+	writtento(new bool[this->size()]())
+      { }
 
       ~OutputContainer()
       { delete[] writtento; }
@@ -86,13 +87,14 @@ namespace __gnu_test
 
     public:
       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)
       { }
 
 #if __cplusplus >= 201103L
       template<class U>
-      void
+      typename std::enable_if<std::is_assignable<T&, U>::value>::type
       operator=(U&& new_val)
       {
 	ITERATOR_VERIFY(SharedInfo->writtento[ptr - SharedInfo->first] == 0);
@@ -182,10 +184,14 @@ namespace __gnu_test
     void operator,(const T&, const output_iterator_wrapper<U>&) = delete;
 #endif
 
+#if __cplusplus >= 2011L
+  using std::remove_cv;
+#else
   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<volatile T> { typedef T type; };
   template<typename T> struct remove_cv<const volatile T> { typedef T type; };
+#endif
 
   /**
    * @brief input_iterator wrapper for pointer
@@ -543,6 +549,7 @@ namespace __gnu_test
   struct test_container
   {
     typename ItType<T>::ContainerType bounds;
+
     test_container(T* _first, T* _last) : bounds(_first, _last)
     { }
 
@@ -556,7 +563,7 @@ namespace __gnu_test
     ItType<T>
     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);
     }
 
@@ -581,7 +588,7 @@ namespace __gnu_test
 
     std::size_t
     size() const
-    { return bounds.last - bounds.first; }
+    { return bounds.size(); }
   };
 }
 #endif

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Minor improvements to testsuite iterator utilities
  2019-10-29 17:15 [PATCH] Minor improvements to testsuite iterator utilities Jonathan Wakely
@ 2019-10-30 14:34 ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2019-10-30 14:34 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 682 bytes --]

On 29/10/19 17:15 +0000, Jonathan Wakely wrote:
>	* 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().
>
>Tested powerpc64le-linux, committed to trunk.


>@@ -182,10 +184,14 @@ namespace __gnu_test
>     void operator,(const T&, const output_iterator_wrapper<U>&) = delete;
> #endif
>
>+#if __cplusplus >= 2011L

Oops! That should be 201103L.

Fixed by the attached patch, which I'll commit shortly.


[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 817 bytes --]

commit 069df87c7e936d568a142df3930c700306546acc
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Oct 30 14:32:53 2019 +0000

    Fix typo in preprocessor check
    
            * testsuite/util/testsuite_iterators.h: Fix typo in __cplusplus check.

diff --git a/libstdc++-v3/testsuite/util/testsuite_iterators.h b/libstdc++-v3/testsuite/util/testsuite_iterators.h
index 70c1f9b6689..c5ae5b123fe 100644
--- a/libstdc++-v3/testsuite/util/testsuite_iterators.h
+++ b/libstdc++-v3/testsuite/util/testsuite_iterators.h
@@ -184,7 +184,7 @@ namespace __gnu_test
     void operator,(const T&, const output_iterator_wrapper<U>&) = delete;
 #endif
 
-#if __cplusplus >= 2011L
+#if __cplusplus >= 201103L
   using std::remove_cv;
 #else
   template<typename T> struct remove_cv { typedef T type; };

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-10-30 14:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-29 17:15 [PATCH] Minor improvements to testsuite iterator utilities Jonathan Wakely
2019-10-30 14:34 ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).