• For what is this class good for ?

    From Bonita Montero@Bonita.Montero@gmail.com to comp.lang.c++ on Wed Oct 8 18:48:34 2025
    From Newsgroup: comp.lang.c++

    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();
    }
    }
    };


    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Bonita Montero@Bonita.Montero@gmail.com to comp.lang.c++ on Wed Oct 8 19:07:09 2025
    From Newsgroup: comp.lang.c++

    Am 08.10.2025 um 18:48 schrieb Bonita Montero:

    ...
    template<typename ... PassThrough>
    struct exc_xguard
    {
    -a-a-a-atemplate<typename Func, typename Nested>
    -a-a-a-aFORCEINLINE auto operator ()( Func func, Nested nested ) const
    -a-a-a-a{
    -a-a-a-a-a-a-a static_assert( sizeof ...(PassThrough) >= 1 );
    -a-a-a-a-a-a-a try
    -a-a-a-a-a-a-a {
    -a-a-a-a-a-a-a-a-a-a-a using return_type = std::invoke_result_t<Func>;
    -a-a-a-a-a-a-a-a-a-a-a return [&]<typename ... Pass>( this auto const &self,
    std::tuple<Pass *...> ) L_FORCEINLINE -> return_type
    -a-a-a-a-a-a-a-a-a-a-a-a-a-a-a {
    -a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a try
    -a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a {
    -a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a if constexpr( sizeof ...(Pass) == 1 )
    -a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a return func();
    -a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a else
    -a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a return self( typename
    exc_xguard_unpack_last<Pass ...>::further() );
    -a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a }
    -a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a catch( typename exc_xguard_unpack_last<Pass ...>::type & )
    -a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a {
    -a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a throw;
    -a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a }
    -a-a-a-a-a-a-a-a-a-a-a-a-a-a-a }( std::tuple<PassThrough *...>() );
    -a-a-a-a-a-a-a }
    -a-a-a-a-a-a-a catch( ... )
    -a-a-a-a-a-a-a {
    -a-a-a-a-a-a-a-a-a-a-a throw nested();
    -a-a-a-a-a-a-a }
    -a-a-a-a}
    };



    I forget a throw_with_nested:

    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( ... )
    {
    std::throw_with_nested( nested() );
    }
    }
    };
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From wij@wyniijj5@gmail.com to comp.lang.c++ on Thu Oct 9 01:45:22 2025
    From Newsgroup: comp.lang.c++

    On Wed, 2025-10-08 at 18:48 +0200, Bonita Montero wrote:
    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.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Bonita Montero@Bonita.Montero@gmail.com to comp.lang.c++ on Thu Oct 9 05:47:11 2025
    From Newsgroup: comp.lang.c++

    Am 08.10.2025 um 19:45 schrieb wij:

    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.

    For skilled C++-developers the purpose is easy to guess from the source.

    --- Synchronet 3.21a-Linux NewsLink 1.2