Skip to content

Commit 30f12a4

Browse files
committed
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
llvm-svn: 366776
1 parent 57d17ec commit 30f12a4

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

libcxx/include/bit

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ namespace std {
4242
template<class T>
4343
constexpr int popcount(T x) noexcept; // C++20
4444
45+
// 20.15.9, endian
46+
enum class endian {
47+
little = see below, // C++20
48+
big = see below, // C++20
49+
native = see below // C++20
50+
};
51+
4552
} // namespace std
4653
4754
*/
@@ -456,6 +463,20 @@ log2p1(_Tp __t) noexcept
456463
return __t == 0 ? 0 : __bit_log2(__t) + 1;
457464
}
458465

466+
467+
enum class endian
468+
{
469+
little = 0xDEAD,
470+
big = 0xFACE,
471+
#if defined(_LIBCPP_LITTLE_ENDIAN)
472+
native = little
473+
#elif defined(_LIBCPP_BIG_ENDIAN)
474+
native = big
475+
#else
476+
native = 0xCAFE
477+
#endif
478+
};
479+
459480
#endif // _LIBCPP_STD_VER > 17
460481

461482
_LIBCPP_END_NAMESPACE_STD

libcxx/include/type_traits

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3985,21 +3985,6 @@ struct __can_extract_map_key<_ValTy, _Key, _Key, _RawValTy>
39853985

39863986
#endif
39873987

3988-
#if _LIBCPP_STD_VER > 17
3989-
enum class endian
3990-
{
3991-
little = 0xDEAD,
3992-
big = 0xFACE,
3993-
#if defined(_LIBCPP_LITTLE_ENDIAN)
3994-
native = little
3995-
#elif defined(_LIBCPP_BIG_ENDIAN)
3996-
native = big
3997-
#else
3998-
native = 0xCAFE
3999-
#endif
4000-
};
4001-
#endif
4002-
40033988
#ifndef _LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED
40043989
#if _LIBCPP_STD_VER > 17
40053990
_LIBCPP_INLINE_VISIBILITY

libcxx/test/std/utilities/meta/meta.type.synop/endian.pass.cpp renamed to libcxx/test/std/numerics/bit/bit.endian/endian.pass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
1010

1111
// enum class endian;
12+
// <bit>
1213

13-
#include <type_traits>
14+
#include <bit>
1415
#include <cstring>
1516
#include <cassert>
1617
#include <cstdint>

0 commit comments

Comments
 (0)