VCCC  2024.05
VisualCamp Common C++ library
as_bytes.hpp
Go to the documentation of this file.
1 //
2 // Created by yonggyulee on 2023/12/30.
3 //
4 
5 #ifndef VCCC_SPAN_AS_BYTES_HPP
6 #define VCCC_SPAN_AS_BYTES_HPP
7 
8 #include <cstddef>
9 
10 #include "vccc/__core/byte.hpp"
12 #include "vccc/__span/span.hpp"
13 
14 namespace vccc {
15 namespace detail {
16 
17 template<typename T, std::size_t N>
18 struct as_bytes_size : std::integral_constant<std::size_t, sizeof(T) * N> {};
19 template<typename T>
20 struct as_bytes_size<T, dynamic_extent> : std::integral_constant<std::size_t, dynamic_extent> {};
21 
22 } // namespace detail
23 
26 
35 template<typename T, std::size_t N>
37 as_bytes(span<T, N> s) noexcept {
39  reinterpret_cast<const byte*>(s.data()),
40  s.size_bytes()
41  );
42 }
43 
51  reinterpret_cast<byte*>(s.data()),
52  s.size_bytes()
53  );
54 }
55 
57 
58 } // namespace vccc
59 
60 #endif // VCCC_SPAN_AS_BYTES_HPP
a non-owning view over a contiguous sequence of objects
Definition: span.hpp:118
constexpr span< byte, detail::as_bytes_size< T, N >::value > as_writable_bytes(span< T, N > s) noexcept
converts a span into a view of its underlying bytes
Definition: as_bytes.hpp:49
constexpr span< const byte, detail::as_bytes_size< T, N >::value > as_bytes(span< T, N > s) noexcept
converts a span into a view of its underlying bytes
Definition: as_bytes.hpp:37
constexpr VCCC_INLINE_OR_STATIC std::size_t dynamic_extent
Definition: dynamic_extent.hpp:18
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35