pabigot  0.1.1
C++ support classes
ccbysa30.hpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: (Apache-2.0 & CC-BY-SA-3.0) */
2 
10 #ifndef PABIGOT_EXTERNAL_CCBYSA30_HPP
11 #define PABIGOT_EXTERNAL_CCBYSA30_HPP
12 #pragma once
13 
14 #include <cinttypes>
15 #include <climits>
16 #include <type_traits>
17 #include <utility>
18 
19 namespace pabigot {
20 namespace external {
21 
26 namespace ccbysa30 {
27 
28 namespace details {
29 
34 template<class T,
35  std::size_t... N>
36 constexpr T
37 bswap_impl(T i, std::index_sequence<N...>)
38 {
39  return ((((i >> (N * CHAR_BIT)) & std::uint8_t(-1))
40  << ((sizeof(T) - 1 - N) * CHAR_BIT))
41  | ...);
42 }
43 
44 } // ns details
45 
50 template<class T,
51  class U = typename std::make_unsigned<T>::type>
52 constexpr U
53 bswap(T i)
54 {
55  return details::bswap_impl<U>(i, std::make_index_sequence<sizeof(T)>{});
56 }
57 
58 } // ns external
59 } // ns external
60 } // ns pabigot
61 
62 #endif /* PABIGOT_EXTERNAL_CCBYSA30_HPP */
pabigot::external::ccbysa30::bswap
constexpr U bswap(T i)
C++17 constexpr byte-swapping implementation.
Definition: ccbysa30.hpp:53
pabigot::external::ccbysa30::details::bswap_impl
constexpr T bswap_impl(T i, std::index_sequence< N... >)
C++17 constexpr byte-swapping implementation.
Definition: ccbysa30.hpp:37
pabigot
Root for all pabigot namespaces.
Definition: gap.hpp:15