pw_bytes: Use std::endian as pw::endian when it is available
Change-Id: Ic1e86beaed8f35e91a262744676952753bb0abef
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/97904
Reviewed-by: Armando Montanez <amontanez@google.com>
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
diff --git a/pw_bytes/docs.rst b/pw_bytes/docs.rst
index 6645642..a625fe0 100644
--- a/pw_bytes/docs.rst
+++ b/pw_bytes/docs.rst
@@ -47,7 +47,8 @@
Implementation of features provided by C++20's ``<bit>`` header. Supported
features:
-* ``pw::endian`` -- Implementation of the ``std::endian`` enum.
+* ``pw::endian`` -- Implementation of the ``std::endian`` enum. If
+ ``std::endian`` is available, ``pw::endian`` is an alias of it.
pw_bytes/endian.h
=================
diff --git a/pw_bytes/public/pw_bytes/bit.h b/pw_bytes/public/pw_bytes/bit.h
index 33ac621..c712719 100644
--- a/pw_bytes/public/pw_bytes/bit.h
+++ b/pw_bytes/public/pw_bytes/bit.h
@@ -15,9 +15,17 @@
// Features from the <bit> header introduced in C++20.
#pragma once
+#if __has_include(<bit>)
+#include <bit>
+#endif // __has_include(<bit>)
+
namespace pw {
-#if defined(__GNUC__)
+#ifdef __cpp_lib_endian
+
+using std::endian;
+
+#elif defined(__GNUC__)
enum class endian {
little = __ORDER_LITTLE_ENDIAN__,
@@ -31,6 +39,6 @@
"The pw::endian enum is not defined for this compiler. Add a "
"definition to pw_bytes/bit.h.");
-#endif // defined(__GNUC__)
+#endif // __cpp_lib_endian
} // namespace pw