-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added C++20 <bit>, added to <type_traits>, fixed __NOEXCEPT in C++98 (#…
…536)
- Loading branch information
1 parent
4f00ea9
commit bbb2b81
Showing
4 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// -*- C++ -*- | ||
#ifndef _EZCXX_BIT | ||
#define _EZCXX_BIT | ||
|
||
#include <cstring> // for memcpy | ||
#include <type_traits> | ||
|
||
#pragma clang system_header | ||
|
||
namespace std { | ||
|
||
enum class endian { | ||
little = __ORDER_LITTLE_ENDIAN__, | ||
big = __ORDER_BIG_ENDIAN__, | ||
native = __BYTE_ORDER__ | ||
}; // endian | ||
|
||
template<class _To, class _From> | ||
std::enable_if_t< | ||
sizeof(_To) == sizeof(_From) && | ||
std::is_trivially_copyable_v<_From> && | ||
std::is_trivially_copyable_v<_To>, _To> | ||
constexpr bit_cast(const _From& src) noexcept { | ||
static_assert(std::is_trivially_constructible_v<_To>, | ||
"destination type is required to be trivially constructible"); | ||
_To dst; | ||
std::memcpy(&dst, &src, sizeof(_To)); | ||
return dst; | ||
} | ||
|
||
} // namespace std | ||
|
||
#endif // _EZCXX_BIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters