Exception filter
From
Bonita Montero@3:633/10 to
All on Wed Oct 22 05:06:20 2025
Nice, isn't it ?
template<typename First, typename ... Further>
struct exc_xguard_unpack_last
{
using further = std::tuple<Further *...>;
using type = typename exc_xguard_unpack_last<Further ...>::type;
};
template<typename Last>
struct exc_xguard_unpack_last<Last>
{
using type = Last;
};
template<typename ... PassThrough>
requires (sizeof ...(PassThrough) >= 1)
struct exc_xguard
{
template<typename Func, typename Nested>
FORCEINLINE auto operator ()( Func func, Nested nested ) const
{
try
{
using return_type = std::invoke_result_t<Func>;
return [&]<typename ... Pass>( this auto const &self, std::tuple<Pass
*...> ) L_FORCEINLINE -> return_type
{
try
{
if constexpr( sizeof ...(Pass) == 1 )
return func();
else
return self( typename exc_xguard_unpack_last<Pass ...>::further() );
}
catch( typename exc_xguard_unpack_last<Pass ...>::type & )
{
throw;
}
}( std::tuple<PassThrough *...>() );
}
catch( ... )
{
std::throw_with_nested( nested() );
}
}
};
--- PyGate Linux v1.5
* Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)