...
template<typename ... PassThrough>
struct exc_xguard
{
˙˙˙˙template<typename Func, typename Nested>
˙˙˙˙FORCEINLINE auto operator ()( Func func, Nested nested ) const
˙˙˙˙{
˙˙˙˙˙˙˙ static_assert( sizeof ...(PassThrough) >= 1 );
˙˙˙˙˙˙˙ 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( ... )
˙˙˙˙˙˙˙ {
˙˙˙˙˙˙˙˙˙˙˙ throw nested();
˙˙˙˙˙˙˙ }
˙˙˙˙}
};
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>
struct exc_xguard
{
template<typename Func, typename Nested>
FORCEINLINE auto operator ()( Func func, Nested nested ) const
{
static_assert( sizeof ...(PassThrough) >= 1 );
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( ... )
{
throw nested();
}
}
};
As usual, the code itself is meaningless (likely so?).
What is the purpose of the codes, and useful in what environment/condition?
C++ is expressive. But more importantly, expressive for what? If the author is
not clear of the logic of his idea/concept, what would the 'expressive' mean? That is the general C++ problem: It greatly helps writing obscure codes.
Sysop: | Tetrazocine |
---|---|
Location: | Melbourne, VIC, Australia |
Users: | 14 |
Nodes: | 8 (0 / 8) |
Uptime: | 187:33:52 |
Calls: | 178 |
Files: | 21,502 |
Messages: | 79,849 |