QuickCppLib 0.10
Eliminate all the tedious hassle when making state-of-the-art C++ 14 - 23 libraries!
Loading...
Searching...
No Matches
quickcpplib::_xxx::in_place_attach_detach Namespace Reference

Namespaces

namespace  traits
 Namespace for user specialised traits.
namespace  detail

Classes

struct  adopt_t
class  attached
 An RAII refinement of span<T> for automatically calling in_place_attach() and in_place_detach() on an input array of T. Move-only, detaches only on final object destruction. More...

Functions

template<class T, typename = decltype(detach_cast(std::declval<T>()))>
constexpr auto in_place_detach (quickcpplib::_xxx::span::span< T > objects, detail::default_cast_operator_overload={}) noexcept
 An ADL customisation point for the in-place detachment of an array of live T objects into an array of bytes representing their detached object representations. This overload is available if detach_cast() is available for T.
template<class T, typename = decltype(attach_cast<T>(std::declval< quickcpplib::_xxx::detach_cast::byte_array_reference<T>>()))>
constexpr quickcpplib::_xxx::span::span< T > in_place_attach (quickcpplib::_xxx::span::span< quickcpplib::_xxx::byte::byte > bytearray, detail::default_cast_operator_overload={}) noexcept
 An ADL customisation point for the in-place attachment of previously detached object representations, back into an array of live T objects. This overload is available if attach_cast() is available for T.
template<class T, typename std::enable_if<(!detail::is_bit_cast_valid< T, detail::byte_array_wrapper< T > >() &&!traits::enable_reinterpret_attach_cast< typename std::decay< T >::type >::value), bool >::type = true>
QUICKCPPLIB_NODISCARD constexpr T & attach_cast (const_byte_array_reference< T > &,...) noexcept
 Reattaches a previously detached object, beginning the lifetime of the output object, and ending the lifetime of the input array of byte. All references to the input byte array become INVALID. Any use of the input array after attachment has occurred is illegal!

Variables

constexpr adopt_t adopt {}

Function Documentation

◆ in_place_detach()

template<class T, typename = decltype(detach_cast(std::declval<T>()))>
auto quickcpplib::_xxx::in_place_attach_detach::in_place_detach ( quickcpplib::_xxx::span::span< T > objects,
detail::default_cast_operator_overload = {} )
inlineconstexprnoexcept

An ADL customisation point for the in-place detachment of an array of live T objects into an array of bytes representing their detached object representations. This overload is available if detach_cast() is available for T.

62 {}) noexcept
63 {
64 using byte_type = typename std::conditional<std::is_const<T>::value, const QUICKCPPLIB_NAMESPACE::byte::byte, QUICKCPPLIB_NAMESPACE::byte::byte>::type;
65 QUICKCPPLIB_NAMESPACE::span::span<byte_type> ret;
66 if(objects.empty())
67 {
68 ret = QUICKCPPLIB_NAMESPACE::span::span<byte_type>((byte_type *) objects.data(), (byte_type *) objects.data());
69 return ret;
70 }
71 for(size_t n = 0; n < objects.size(); n++)
72 {
73 auto &d = detach_cast(objects[n]);
74 if(0 == n)
75 {
76 ret = {d, sizeof(d)};
77 }
78 else
79 {
80 ret = {ret.data(), ret.size() + sizeof(d)};
81 }
82 }
83 return ret;
84 }

◆ in_place_attach()

template<class T, typename = decltype(attach_cast<T>(std::declval< quickcpplib::_xxx::detach_cast::byte_array_reference<T>>()))>
quickcpplib::_xxx::span::span< T > quickcpplib::_xxx::in_place_attach_detach::in_place_attach ( quickcpplib::_xxx::span::span< quickcpplib::_xxx::byte::byte > bytearray,
detail::default_cast_operator_overload = {} )
inlineconstexprnoexcept

An ADL customisation point for the in-place attachment of previously detached object representations, back into an array of live T objects. This overload is available if attach_cast() is available for T.

92 {}) noexcept
93 {
94 QUICKCPPLIB_NAMESPACE::span::span<detail::byte_array_wrapper<T>> input = {(detail::byte_array_wrapper<T> *) bytearray.data(), bytearray.size() / sizeof(T)};
95 QUICKCPPLIB_NAMESPACE::span::span<T> ret;
96 if(bytearray.empty())
97 {
98 ret = QUICKCPPLIB_NAMESPACE::span::span<T>((T *) bytearray.data(), (T *) bytearray.data());
99 return ret;
100 }
101 for(size_t n = 0; n < input.size(); n++)
102 {
103 T &a = attach_cast<T>(input[n].value);
104 if(0 == n)
105 {
106 ret = {&a, 1};
107 }
108 else
109 {
110 ret = {ret.data(), ret.size() + 1};
111 }
112 }
113 return ret;
114 }
quickcpplib::_xxx::detach_cast::detail::byte_array_wrapper< T > byte_array_wrapper
Definition in_place_detach_attach.hpp:50
QUICKCPPLIB_NODISCARD constexpr T & attach_cast(const_byte_array_reference< T > &,...) noexcept
Reattaches a previously detached object, beginning the lifetime of the output object,...
Definition detach_cast.hpp:141

◆ attach_cast()

template<class T, typename std::enable_if<(!detail::is_bit_cast_valid< T, detail::byte_array_wrapper< T > >() &&!traits::enable_reinterpret_attach_cast< typename std::decay< T >::type >::value), bool >::type = true>
QUICKCPPLIB_NODISCARD constexpr T & quickcpplib::_xxx::detach_cast::attach_cast ( const_byte_array_reference< T > & ,
... )
inlineconstexprnoexcept

Reattaches a previously detached object, beginning the lifetime of the output object, and ending the lifetime of the input array of byte. All references to the input byte array become INVALID. Any use of the input array after attachment has occurred is illegal!

Implementation notes: If the output type is bit castable, bit casting is used to implement attachment using defined behaviour in C++ 20. Otherwise traits::enable_reinterpret_attach_cast<T> is used to determine whether to implement attachment using undefined behaviour by reinterpret casting.

142 { //
143 static_assert(!std::is_same<T, T>::value, "In C++ 20, attach_cast(T) is defined behaviour only for types which are bit castable. " //
144 "Set traits::enable_reinterpret_attach_cast<T> for specific types if you don't mind undefined behaviour.");
145 }

Variable Documentation

◆ adopt

adopt_t quickcpplib::_xxx::in_place_attach_detach::adopt {}
constexpr
119{};