Wyatt Hepler | 0412a7d | 2020-01-28 16:27:32 -0800 | [diff] [blame] | 1 | // Copyright 2020 The Pigweed Authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 4 | // use this file except in compliance with the License. You may obtain a copy of |
| 5 | // the License at |
| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | // License for the specific language governing permissions and limitations under |
| 13 | // the License. |
| 14 | #pragma once |
| 15 | |
| 16 | #include <stddef.h> |
| 17 | |
Wyatt Hepler | 023f35b | 2020-07-01 09:40:50 -0700 | [diff] [blame] | 18 | #include "pw_polyfill/standard_library/namespace.h" |
| 19 | |
| 20 | _PW_POLYFILL_BEGIN_NAMESPACE_STD |
Wyatt Hepler | 0412a7d | 2020-01-28 16:27:32 -0800 | [diff] [blame] | 21 | |
| 22 | using ::ptrdiff_t; |
| 23 | using ::size_t; |
| 24 | using nullptr_t = decltype(nullptr); |
| 25 | using ::max_align_t; |
| 26 | |
| 27 | #define __cpp_lib_byte 201603L |
| 28 | |
| 29 | enum class byte : unsigned char {}; |
| 30 | |
| 31 | template <typename I> |
| 32 | constexpr I to_integer(byte b) noexcept { |
| 33 | return I(b); |
| 34 | } |
| 35 | |
| 36 | constexpr byte operator|(byte l, byte r) noexcept { |
| 37 | return byte(static_cast<unsigned int>(l) | static_cast<unsigned int>(r)); |
| 38 | } |
| 39 | |
| 40 | constexpr byte operator&(byte l, byte r) noexcept { |
| 41 | return byte(static_cast<unsigned int>(l) & static_cast<unsigned int>(r)); |
| 42 | } |
| 43 | |
| 44 | constexpr byte operator^(byte l, byte r) noexcept { |
| 45 | return byte(static_cast<unsigned int>(l) ^ static_cast<unsigned int>(r)); |
| 46 | } |
| 47 | |
| 48 | constexpr byte operator~(byte b) noexcept { |
| 49 | return byte(~static_cast<unsigned int>(b)); |
| 50 | } |
| 51 | |
| 52 | template <typename I> |
| 53 | constexpr byte operator<<(byte b, I shift) noexcept { |
| 54 | return byte(static_cast<unsigned int>(b) << shift); |
| 55 | } |
| 56 | |
| 57 | template <typename I> |
| 58 | constexpr byte operator>>(byte b, I shift) noexcept { |
| 59 | return byte(static_cast<unsigned int>(b) >> shift); |
| 60 | } |
| 61 | |
| 62 | constexpr byte& operator|=(byte& l, byte r) noexcept { return l = l | r; } |
| 63 | constexpr byte& operator&=(byte& l, byte r) noexcept { return l = l & r; } |
| 64 | constexpr byte& operator^=(byte& l, byte r) noexcept { return l = l ^ r; } |
| 65 | |
| 66 | template <typename I> |
| 67 | inline byte& operator<<=(byte& b, I shift) noexcept { |
| 68 | return b = b << shift; |
| 69 | } |
| 70 | |
| 71 | template <typename I> |
| 72 | inline byte& operator>>=(byte& b, I shift) noexcept { |
| 73 | return b = b >> shift; |
| 74 | } |
| 75 | |
Wyatt Hepler | 023f35b | 2020-07-01 09:40:50 -0700 | [diff] [blame] | 76 | _PW_POLYFILL_END_NAMESPACE_STD |