35 static_assert(std::is_trivial_v<T>);
47 : native_(std::move(
native)) {}
62 constexpr operator T&()
noexcept {
67 constexpr operator const T&()
const noexcept {
87 constexpr const T*
handle() const noexcept {
93 std::swap(this->
native(), other.native());
102 constexpr const T&
native() const noexcept {
121 template <
typename U>
122 static std::true_type check(
const Wrapper<U>&);
123 static std::false_type check(...);
125 using type =
decltype(check(std::declval<T&>()));
126 static constexpr bool value = type::value;
135template <
typename WrapperType>
136struct WrapperConversion {
137 static_assert(detail::IsWrapper<WrapperType>::value);
138 static_assert(std::is_standard_layout_v<WrapperType>);
140 using NativeType =
typename WrapperType::NativeType;
143 static constexpr WrapperType* asWrapper(NativeType* native)
noexcept {
144 return static_cast<WrapperType*
>(
static_cast<void*
>(native));
147 static constexpr const WrapperType* asWrapper(
const NativeType* native)
noexcept {
148 return static_cast<const WrapperType*
>(
static_cast<const void*
>(native));
151 static constexpr WrapperType& asWrapper(NativeType& native)
noexcept {
152 return *asWrapper(&native);
155 static constexpr const WrapperType& asWrapper(
const NativeType& native)
noexcept {
156 return *asWrapper(&native);
159 static constexpr NativeType* asNative(WrapperType* wrapper)
noexcept {
160 return static_cast<NativeType*
>(
static_cast<void*
>(wrapper));
163 static constexpr const NativeType* asNative(
const WrapperType* wrapper)
noexcept {
164 return static_cast<const NativeType*
>(
static_cast<const void*
>(wrapper));
167 static constexpr NativeType& asNative(WrapperType& wrapper)
noexcept {
168 return *asNative(&wrapper);
171 static constexpr const NativeType& asNative(
const WrapperType& wrapper)
noexcept {
172 return *asNative(&wrapper);
189template <
typename WrapperType,
typename NativeType =
typename WrapperType::NativeType>
191 return detail::WrapperConversion<WrapperType>::asWrapper(native);
196template <
typename WrapperType,
typename NativeType =
typename WrapperType::NativeType>
198 return detail::WrapperConversion<WrapperType>::asWrapper(native);
204template <
typename WrapperType,
typename NativeType =
typename WrapperType::NativeType>
206 return detail::WrapperConversion<WrapperType>::asWrapper(native);
211template <
typename WrapperType,
typename NativeType =
typename WrapperType::NativeType>
213 return detail::WrapperConversion<WrapperType>::asWrapper(native);
219template <
typename WrapperType,
typename NativeType =
typename WrapperType::NativeType>
221 return detail::WrapperConversion<WrapperType>::asNative(wrapper);
226template <
typename WrapperType,
typename NativeType =
typename WrapperType::NativeType>
228 return detail::WrapperConversion<WrapperType>::asNative(wrapper);
234template <
typename WrapperType,
typename NativeType =
typename WrapperType::NativeType>
236 return detail::WrapperConversion<WrapperType>::asNative(wrapper);
241template <
typename WrapperType,
typename NativeType =
typename WrapperType::NativeType>
243 return detail::WrapperConversion<WrapperType>::asNative(wrapper);
Template base class to wrap native objects.
constexpr Wrapper & operator=(const T &native) noexcept
Copy assignment with native object.
constexpr void swap(Wrapper &other) noexcept
Swap with wrapper object.
constexpr const T * operator->() const noexcept
Member access to native object.
constexpr T * operator->() noexcept
Member access to native object.
constexpr const T & native() const noexcept
constexpr const T * handle() const noexcept
Return pointer to native object.
constexpr T & native() noexcept
constexpr T * handle() noexcept
Return pointer to native object.
constexpr void swap(T &native) noexcept
Swap with native object.
constexpr Wrapper(T &&native) noexcept
Move constructor with native object.
constexpr Wrapper() noexcept=default
constexpr Wrapper & operator=(T &&native) noexcept
Move assignment with native object.
constexpr WrapperType & asWrapper(NativeType &native) noexcept
Cast native object references to Wrapper object references.
constexpr NativeType * asNative(WrapperType *wrapper) noexcept
Cast Wrapper object pointers to native object pointers.
constexpr const WrapperType & asWrapper(const NativeType &native) noexcept
Cast native object references to Wrapper object references.
constexpr WrapperType * asWrapper(NativeType *native) noexcept
Cast native object pointers to Wrapper object pointers.
constexpr NativeType & asNative(WrapperType &wrapper) noexcept
Cast Wrapper object references to native object references.
constexpr const WrapperType * asWrapper(const NativeType *native) noexcept
Cast native object pointers to Wrapper object pointers.
constexpr const NativeType & asNative(const WrapperType &wrapper) noexcept
Cast Wrapper object references to native object references.
constexpr const NativeType * asNative(const WrapperType *wrapper) noexcept
Cast Wrapper object pointers to native object pointers.