9template <
typename T,
typename U>
12 if constexpr ( std::is_const_v<U> )
13 return reinterpret_cast<const T*
>( from );
15 return reinterpret_cast<T*
>( from );
18template <
typename T,
typename U>
21 if constexpr ( std::is_const_v<U> )
22 return reinterpret_cast<const T&
>( from );
24 return reinterpret_cast<T&
>( from );
27template <
typename T,
typename U>
30 return reinterpret_cast<T&&
>( from );
40 using Base = std::remove_const_t<std::remove_pointer_t<std::remove_reference_t<U>>>;
41 if constexpr ( std::is_arithmetic_v<Base> )
48 return cast_to<T>( std::forward<U&&>( from ) );
53#define ADD_AUTO_CAST( From, To ) \
54template <> struct auto_cast_trait<From> { using target_type = To; }
57#define REGISTER_AUTO_CAST2( Type1, Type2 ) \
58ADD_AUTO_CAST( Type1, Type2 ); \
59ADD_AUTO_CAST( Type2, Type1 );
61#define REGISTER_AUTO_CAST( Type ) \
62REGISTER_AUTO_CAST2( Type, MR_CONCAT( MR, Type ) )
73auto&& X = *auto_cast( MR_CONCAT( X, _ ) )
77auto&& X = auto_cast( MR_CONCAT( X, _ ) )
81auto&& X = auto_cast( MR_CONCAT( X, _ ) )
84#define ARG_OF( Type, X ) \
85auto&& X = *cast_to<Type>( MR_CONCAT( X, _ ) )
88#define ARG_PTR_OF( Type, X ) \
89auto&& X = cast_to<Type>( MR_CONCAT( X, _ ) )
92#define ARG_VAL_OF( Type, X ) \
93auto&& X = cast_to<Type>( MR_CONCAT( X, _ ) )
96#define RETURN( ... ) \
97return auto_cast( __VA_ARGS__ )
100template <
typename T,
typename U = std::remove_cvref_t<T>>
103 return new U( std::forward<T&&>( a ) );
107#define RETURN_NEW( ... ) \
108return auto_cast( new_from( __VA_ARGS__ ) )
111#define RETURN_NEW_OF( Type, ... ) \
112return auto_cast( new_from<Type>( __VA_ARGS__ ) )
auto auto_cast(U &&from)
helper function to cast to an associated type
Definition TypeCast.h:38
auto cast_to(U *from)
helper functions to cast types without explicit qualifiers
Definition TypeCast.h:10
U * new_from(T &&a)
helper function to allocate a new object of auto-detected type
Definition TypeCast.h:101