E.V.E
v2023.02.15
 
Loading...
Searching...
No Matches
/__w/eve/eve/include/eve/traits/as_translation.hpp

Translates an as type wrapper to a type wrapper of its translated type.

Translates an as type wrapper to a type wrapper of its translated type.

Template Parameters
VThe wrapper type to translate
Returns
Type tag for the translated type
enum class E: int { };
static_assert(std::same_as<decltype(eve::translate(tag)), eve::as<int>>);
constexpr translate_t< V > translate(V const &val)
Translates a value to its translated type.
Definition as_translation.hpp:28
Lightweight type-wrapper.
Definition as.hpp:29
//==================================================================================================
/*
EVE - Expressive Vector Engine
Copyright : EVE Project Contributors
SPDX-License-Identifier: BSL-1.0
*/
//==================================================================================================
#pragma once
#include <eve/concept/translation.hpp>
#include <eve/detail/wide_forward.hpp>
#include <eve/memory/pointer.hpp>
#include <eve/traits/value_type.hpp>
#include <eve/traits/pointer.hpp>
#include <bit>
#include <new>
namespace eve
{
//================================================================================================
//================================================================================================
template <typename V>
constexpr translate_t<V> translate(V const& val)
{
if constexpr (has_plain_translation<element_type_t<V>>) return std::bit_cast<translate_t<V>>(val);
else return val;
}
//================================================================================================
//================================================================================================
template <typename T, size_t N>
constexpr std::array<translate_t<T>, N> translate(std::array<T, N> val)
{
if constexpr (has_plain_translation<element_type_t<T>>) return std::bit_cast<std::array<translate_t<T>, N>>(val);
else return val;
}
//================================================================================================
//================================================================================================
template <typename V>
{
return reinterpret_cast<translate_t<V>&>(val);
}
//================================================================================================
//================================================================================================
template <typename V>
constexpr auto translate(as<V>)
{
return as<translate_t<V>>{};
}
//================================================================================================
//================================================================================================
template <detail::scalar_pointer Ptr>
constexpr auto translate_ptr(Ptr ptr)
{
{
using trans_t = detail::copy_qualifiers_t<translated_value_type_t<Ptr>, Ptr>;
if constexpr (std::is_pointer_v<Ptr>)
{
return std::launder(reinterpret_cast<trans_t*>(ptr));
}
else
{
return std::bit_cast<typename Ptr::template rebind<trans_t>>(ptr);
}
}
else
{
return ptr;
}
}
//================================================================================================
//================================================================================================
template <typename Dst, translatable_into<Dst> Src>
constexpr Dst translate_into(Src const& val, as<Dst>)
{
return std::bit_cast<Dst>(val);
}
}
typename decltype(detail::as_translated_type(as< T >{}))::type translate_t
Returns the final translated type of T.
Definition translation.hpp:107
EVE Main Namespace.
Definition abi.hpp:19