Date: Mon, 11 Mar 2024 10:26:10 +0000
On Mon, Mar 11, 2024 at 10:07 AM Frederick Virchanza Gotham wrote:
>
> Although maybe I could have written a lambda or a template class to do
> away with the preprocessor macroes.
Here it is without the preprocessor macroes:
template<typename Tuple, size_t I>
class CastTo final {
using tElem = tuple_element_t< I, remove_reference_t<Tuple> >;
using tElem_NoRef = remove_reference_t<tElem>;
inline static constexpr bool vElem_IsRef =
!is_same_v<tElem,tElem_NoRef>;
inline static constexpr bool vElem_ShouldBeR =
is_rvalue_reference_v<tElem> || (!vElem_IsRef &&
!is_lvalue_reference_v<Tuple>);
public:
using type = conditional_t< vElem_ShouldBeR , tElem_NoRef&&,
tElem_NoRef& >;
};
template<typename Tuple, size_t I>
using CastTo_t = CastTo<Tuple,I>::type;
template<typename F, typename Tuple, size_t... I>
constexpr decltype(auto) apply_perfectly_impl(F &&f, Tuple &&t,
index_sequence<I...>)
{
return invoke( forward<F>(f), static_cast< CastTo_t<Tuple,I>
>( get<I>(t) )... );
}
I've left out the 'noexcept(noexcept(................))' on both
functions because it's so long.
>
> Although maybe I could have written a lambda or a template class to do
> away with the preprocessor macroes.
Here it is without the preprocessor macroes:
template<typename Tuple, size_t I>
class CastTo final {
using tElem = tuple_element_t< I, remove_reference_t<Tuple> >;
using tElem_NoRef = remove_reference_t<tElem>;
inline static constexpr bool vElem_IsRef =
!is_same_v<tElem,tElem_NoRef>;
inline static constexpr bool vElem_ShouldBeR =
is_rvalue_reference_v<tElem> || (!vElem_IsRef &&
!is_lvalue_reference_v<Tuple>);
public:
using type = conditional_t< vElem_ShouldBeR , tElem_NoRef&&,
tElem_NoRef& >;
};
template<typename Tuple, size_t I>
using CastTo_t = CastTo<Tuple,I>::type;
template<typename F, typename Tuple, size_t... I>
constexpr decltype(auto) apply_perfectly_impl(F &&f, Tuple &&t,
index_sequence<I...>)
{
return invoke( forward<F>(f), static_cast< CastTo_t<Tuple,I>
>( get<I>(t) )... );
}
I've left out the 'noexcept(noexcept(................))' on both
functions because it's so long.
Received on 2024-03-11 10:26:19