Skip to content

Commit

Permalink
pw_polyfill: Update to support detecting C++20
Browse files Browse the repository at this point in the history
- Expand PW_CXX_STANDARD_IS_SUPPORTED() for C++20.
- Remove redundant inline.

Change-Id: I1f56226d30342bdf9e202522fcb6b66fea2072bc
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/95461
Pigweed-Auto-Submit: Wyatt Hepler <[email protected]>
Reviewed-by: Ted Pudlik <[email protected]>
Commit-Queue: Auto-Submit <[email protected]>
  • Loading branch information
255 authored and CQ Bot Account committed May 31, 2022
1 parent bb5fb4e commit e8f3e42
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
21 changes: 16 additions & 5 deletions pw_polyfill/docs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,26 @@ Header Feature Level of support
----------------------------------------------------
Adapt code to compile with different versions of C++
----------------------------------------------------
``pw_polyfill`` provides features for adapting to different C++ standards when
``pw_polyfill:overrides``'s automatic backporting is insufficient:
``pw_polyfill`` provides features for adapting to different C++ standards when
``pw_polyfill:overrides``'s automatic backporting is insufficient.

C++ standard macro
==================
``pw_polyfill/standard.h`` provides a macro for checking if a C++ standard is
supported.

.. c:macro:: PW_CXX_STANDARD_IS_SUPPORTED(standard)
Evaluates true if the provided C++ standard (98, 11, 14, 17, 20) is supported
by the compiler. This is a simpler, cleaner alternative to checking the value
of the ``__cplusplus`` macro.

- ``pw_polyfill/standard.h`` -- provides a macro for checking the C++ standard
- ``pw_polyfill/language_feature_macros.h`` -- provides macros for adapting
code to work with or without newer language features

Language feature macros
=======================
``pw_polyfill/language_feature_macros.h`` provides macros for adapting code to
work with or without newer language features

====================== ================================ ======================================== ==========================
Macro Feature Description Feature test macro
====================== ================================ ======================================== ==========================
Expand Down
1 change: 1 addition & 0 deletions pw_polyfill/public/pw_polyfill/standard.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
#define _PW_CXX_STANDARD_11() 201103L
#define _PW_CXX_STANDARD_14() 201402L
#define _PW_CXX_STANDARD_17() 201703L
#define _PW_CXX_STANDARD_20() 202002L
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ constexpr byte& operator&=(byte& l, byte r) noexcept { return l = l & r; }
constexpr byte& operator^=(byte& l, byte r) noexcept { return l = l ^ r; }

template <typename I>
constexpr inline byte& operator<<=(byte& b, I shift) noexcept {
constexpr byte& operator<<=(byte& b, I shift) noexcept {
return b = b << shift;
}

template <typename I>
constexpr inline byte& operator>>=(byte& b, I shift) noexcept {
constexpr byte& operator>>=(byte& b, I shift) noexcept {
return b = b >> shift;
}

Expand Down
6 changes: 6 additions & 0 deletions pw_polyfill/test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ static_assert(PW_CXX_STANDARD_IS_SUPPORTED(17), "C++17 must be not supported");
static_assert(!PW_CXX_STANDARD_IS_SUPPORTED(17), "C++17 must be supported");
#endif // __cplusplus >= 201703L

#if __cplusplus >= 202002L
static_assert(PW_CXX_STANDARD_IS_SUPPORTED(20), "C++20 must be supported");
#else
static_assert(!PW_CXX_STANDARD_IS_SUPPORTED(20), "C++20 must not be supported");
#endif // __cplusplus >= 202002L

TEST(Bit, Endian) {
if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) {
EXPECT_EQ(std::endian::native, std::endian::big);
Expand Down

0 comments on commit e8f3e42

Please sign in to comment.