This is the mail archive of the mailing list for the libstdc++ project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [v3 PATCH] Reduce the size of variant, it doesn't need an index of type size_t internally.

On 11/01/17 00:19 +0200, Ville Voutilainen wrote:
      { return !this->_M_valid(); }

      constexpr size_t index() const noexcept
-      { return this->_M_index; }
+      {
+	if (this->_M_index ==
+	    typename _Base::_Storage::__index_type(variant_npos))
+	  return variant_npos;
+	return this->_M_index;

GCC doesn't seem to be smart enough to optimize the branch away here.
Something like this would avoid it:

 constexpr size_t index const noexcept
   using __index_type = typename _Base::_Storage::__index_type;
   return size_t(__index_type(this->_M_index + 1)) - 1;

But we can worry about that later.

+      }

      swap(variant& __rhs)
diff --git a/libstdc++-v3/testsuite/20_util/variant/ b/libstdc++-v3/testsuite/20_util/variant/
new file mode 100644
index 0000000..b7f3a7b
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/variant/
@@ -0,0 +1,24 @@
+// { dg-options "-std=gnu++17" }
+// { dg-do compile { target x86_64-*-* powerpc*-*-*} }

Please add a space after the second target (it seems to work anyway,
but still better to add it).

OK for trunk with that space character added, thanks.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]