This patch defines

  operator""zu(unsigned long long __n)

for size_t literals.

for (auto k = 0zul; k < v.size(); ++k)

   ...


Testing on x86-64-linux is finishing but I'm past these tests.

OK?


Ed


2016-07-21  Edward Smith-Rowland  <3dw...@verizon.net>

        Implement C++17 P0330 size_t UDL.
        * include/c_global/cstddef: Add size_t operator""zu().
        * testsuite/18_support/headers/cstddef/literals/types.cc: New test.
        * testsuite/18_support/headers/cstddef/literals/values.cc: New test.

Index: include/c_global/cstddef
===================================================================
--- include/c_global/cstddef    (revision 238557)
+++ include/c_global/cstddef    (working copy)
@@ -57,4 +57,20 @@
 }
 #endif
 
+#if __cplusplus >= 201500L
+#define __cpp_lib_support_udls 201605
+namespace std
+{
+inline namespace literals
+{
+inline namespace support_literals
+{
+  constexpr size_t
+  operator""zu(unsigned long long __n)
+  { return static_cast<size_t>(__n); }
+}
+}
+}
+#endif // C++17
+
 #endif // _GLIBCXX_CSTDDEF
Index: testsuite/18_support/headers/cstddef/literals/types.cc
===================================================================
--- testsuite/18_support/headers/cstddef/literals/types.cc      (nonexistent)
+++ testsuite/18_support/headers/cstddef/literals/types.cc      (working copy)
@@ -0,0 +1,31 @@
+// { dg-options "-std=gnu++17" }
+// { dg-do compile }
+
+// Copyright (C) 2016 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <cstddef>
+#include <type_traits>
+
+void
+test01()
+{
+  using namespace std::literals::support_literals;
+
+  static_assert(std::is_same<decltype(1zu), std::size_t>::value,
+               "1zu is std::size_t");
+}
Index: testsuite/18_support/headers/cstddef/literals/values.cc
===================================================================
--- testsuite/18_support/headers/cstddef/literals/values.cc     (nonexistent)
+++ testsuite/18_support/headers/cstddef/literals/values.cc     (working copy)
@@ -0,0 +1,42 @@
+// { dg-options "-std=gnu++1z" }
+// { dg-do run }
+
+// Copyright (C) 2016 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <cstddef>
+#include <limits>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  using namespace std::literals::support_literals;
+  bool test [[gnu::unused]] = true;
+
+  std::size_t s = 1zu;
+  std::size_t t = -1zu;
+
+  VERIFY( s == 1 );
+  VERIFY( t == std::numeric_limits<std::size_t>::max() );
+}
+
+int
+main()
+{
+  test01();
+}

Reply via email to