[libcxx-commits] [libcxx] r366776 - Implement most of P1612R1: Relocate endian. Moves the std::endian functionality from 'type-traits' to 'bit'. No other change. The reason that this is 'partial' is that P1621 also recommends a feature-test macro, but I don't have the value for that one yet. In a month or so, I'll add that

Marshall Clow via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jul 22 21:20:19 PDT 2019


Author: marshall
Date: Mon Jul 22 21:20:19 2019
New Revision: 366776

URL: http://llvm.org/viewvc/llvm-project?rev=366776&view=rev
Log:
Implement most of P1612R1: Relocate endian.  Moves the std::endian functionality from 'type-traits' to 'bit'. No other change. The reason that this is 'partial' is that P1621 also recommends a feature-test macro, but I don't have the value for that one yet. In a month or so, I'll add that

Added:
    libcxx/trunk/test/std/numerics/bit/bit.endian/
    libcxx/trunk/test/std/numerics/bit/bit.endian/endian.pass.cpp
Removed:
    libcxx/trunk/test/std/utilities/meta/meta.type.synop/endian.pass.cpp
Modified:
    libcxx/trunk/include/bit
    libcxx/trunk/include/type_traits

Modified: libcxx/trunk/include/bit
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/bit?rev=366776&r1=366775&r2=366776&view=diff
==============================================================================
--- libcxx/trunk/include/bit (original)
+++ libcxx/trunk/include/bit Mon Jul 22 21:20:19 2019
@@ -42,6 +42,13 @@ namespace std {
   template<class T>
     constexpr int popcount(T x) noexcept;     // C++20
 
+  // 20.15.9, endian 
+  enum class endian {
+    little = see below,        // C++20
+    big = see below,           // C++20
+    native = see below         // C++20
+};
+
 } // namespace std
 
 */
@@ -456,6 +463,20 @@ log2p1(_Tp __t) noexcept
     return __t == 0 ? 0 : __bit_log2(__t) + 1;
 }
 
+
+enum class endian
+{
+    little = 0xDEAD,
+    big    = 0xFACE,
+#if defined(_LIBCPP_LITTLE_ENDIAN)
+    native = little
+#elif defined(_LIBCPP_BIG_ENDIAN)
+    native = big
+#else
+    native = 0xCAFE
+#endif
+};
+
 #endif // _LIBCPP_STD_VER > 17
 
 _LIBCPP_END_NAMESPACE_STD

Modified: libcxx/trunk/include/type_traits
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/type_traits?rev=366776&r1=366775&r2=366776&view=diff
==============================================================================
--- libcxx/trunk/include/type_traits (original)
+++ libcxx/trunk/include/type_traits Mon Jul 22 21:20:19 2019
@@ -3985,21 +3985,6 @@ struct __can_extract_map_key<_ValTy, _Ke
 
 #endif
 
-#if _LIBCPP_STD_VER > 17
-enum class endian
-{
-    little = 0xDEAD,
-    big    = 0xFACE,
-#if defined(_LIBCPP_LITTLE_ENDIAN)
-    native = little
-#elif defined(_LIBCPP_BIG_ENDIAN)
-    native = big
-#else
-    native = 0xCAFE
-#endif
-};
-#endif
-
 #ifndef _LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED
 #if _LIBCPP_STD_VER > 17
 _LIBCPP_INLINE_VISIBILITY

Added: libcxx/trunk/test/std/numerics/bit/bit.endian/endian.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/bit/bit.endian/endian.pass.cpp?rev=366776&view=auto
==============================================================================
--- libcxx/trunk/test/std/numerics/bit/bit.endian/endian.pass.cpp (added)
+++ libcxx/trunk/test/std/numerics/bit/bit.endian/endian.pass.cpp Mon Jul 22 21:20:19 2019
@@ -0,0 +1,49 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
+
+// enum class endian;
+// <bit>
+
+#include <bit>
+#include <cstring>
+#include <cassert>
+#include <cstdint>
+
+#include "test_macros.h"
+
+int main(int, char**) {
+    static_assert(std::is_enum<std::endian>::value, "");
+
+// Check that E is a scoped enum by checking for conversions.
+    typedef std::underlying_type<std::endian>::type UT;
+    static_assert(!std::is_convertible<std::endian, UT>::value, "");
+
+// test that the enumeration values exist
+    static_assert( std::endian::little == std::endian::little );
+    static_assert( std::endian::big    == std::endian::big );
+    static_assert( std::endian::native == std::endian::native );
+    static_assert( std::endian::little != std::endian::big );
+
+//  Technically not required, but true on all existing machines
+    static_assert( std::endian::native == std::endian::little ||
+                   std::endian::native == std::endian::big );
+
+//  Try to check at runtime
+    {
+    uint32_t i = 0x01020304;
+    char c[4];
+    static_assert(sizeof(i) == sizeof(c));
+    std::memcpy(c, &i, sizeof(c));
+
+    assert ((c[0] == 1) == (std::endian::native == std::endian::big));
+    }
+
+  return 0;
+}

Removed: libcxx/trunk/test/std/utilities/meta/meta.type.synop/endian.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/meta/meta.type.synop/endian.pass.cpp?rev=366775&view=auto
==============================================================================
--- libcxx/trunk/test/std/utilities/meta/meta.type.synop/endian.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/meta/meta.type.synop/endian.pass.cpp (removed)
@@ -1,48 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
-
-// enum class endian;
-
-#include <type_traits>
-#include <cstring>
-#include <cassert>
-#include <cstdint>
-
-#include "test_macros.h"
-
-int main(int, char**) {
-    static_assert(std::is_enum<std::endian>::value, "");
-
-// Check that E is a scoped enum by checking for conversions.
-    typedef std::underlying_type<std::endian>::type UT;
-    static_assert(!std::is_convertible<std::endian, UT>::value, "");
-
-// test that the enumeration values exist
-    static_assert( std::endian::little == std::endian::little );
-    static_assert( std::endian::big    == std::endian::big );
-    static_assert( std::endian::native == std::endian::native );
-    static_assert( std::endian::little != std::endian::big );
-
-//  Technically not required, but true on all existing machines
-    static_assert( std::endian::native == std::endian::little ||
-                   std::endian::native == std::endian::big );
-
-//  Try to check at runtime
-    {
-    uint32_t i = 0x01020304;
-    char c[4];
-    static_assert(sizeof(i) == sizeof(c));
-    std::memcpy(c, &i, sizeof(c));
-
-    assert ((c[0] == 1) == (std::endian::native == std::endian::big));
-    }
-
-  return 0;
-}




More information about the libcxx-commits mailing list