Better way to specify return type in obscure case involving VisualC++ bug?

Discussion in 'C++' started by Alf P. Steinbach, Nov 12, 2013.

  1. As context info, this question originated with the following code
    supporting direct use of the Windows GUI API (properly unpacking and
    dispatching so called "window message" events), where the problematic
    stuff is in the last "->" result type specification:


    Code:
    #pragma once
    // Copyright (c) 2013 Alf P. Steinbach
    
    #include <rfc/cppx/Type_.h>                         // cppx::Type_T_
    #include <rfc/cppx/macros/c++11_features.h>         // CPPX_NOEXCEPT
    #include <rfc/winapi/gui/event/Data.h>              //
    winapi::gui::event::Data, LRESULT
    
    // Invokes e.g. HANDLE_WM_SIZE from <windowsx.h>.
    // The type `This_class` should be accessible to the invocation.
    #define WINAPI_CALL_WM_HANDLER( wm_name, event_handler_func, event_data
    )       \
    ((void) event_data, HANDLE_ ## wm_name(
    \
    &This_class::event_handler_func,
    \
    event_data.w_param(),
    \
    event_data.l_param(),
    \
    call_member<This_class>
    \
    ) )
    
    namespace winapi{ namespace gui{ namespace event{
    using cppx::Type_T_;
    
    class Handler
    {
    private:
    virtual auto on( event::Data const& ) CPPX_NOEXCEPT -> LRESULT = 0;
    
    protected:
    static auto forward_to(
    Handler* const          handler,
    event::Data const&      event_data
    )
    -> LRESULT
    { return handler->on( event_data ); }
    
    template< class Derived, class Member_func, class... Args >
    auto call_member( Member_func const& mf, Args&&... args )
    -> typename Type_T_<decltype( mem_fn( mf ) )>::T::result_type
    { return (static_cast<Derived*>( this )->*mf)( forward<Args>(
    args )... ); }
    };
    
    } } }  // namespace winapi::gui::event
    

    That is, the problem is the sheer verbosity of

    -> typename Type_T_<decltype( mem_fn( mf ) )>::T::result_type

    The Type_T_ template is just a means to get a specified type as a type,
    a workaround for syntactical issues. It typedefs the specified type as
    T. A marginal improvement is to use C++11 "using" and write just

    -> typename Type_<decltype( mem_fn( mf ) )>::result_type

    but Visual C++ 12.0 (2013) chokes on this, in the above context.

    I have the feeling that this can somehow be done in some much betterer way?


    Cheers,

    - Alf
    Alf P. Steinbach, Nov 12, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Frank Millman

    Obscure bug in pyPgSQL

    Frank Millman, Aug 6, 2004, in forum: Python
    Replies:
    2
    Views:
    359
    =?ISO-8859-1?Q?Gerhard_H=E4ring?=
    Aug 6, 2004
  2. Daniel Thoma
    Replies:
    12
    Views:
    1,942
    markspace
    Jul 31, 2009
  3. Chris

    obscure ruby bug tracker

    Chris, Mar 18, 2006, in forum: Ruby
    Replies:
    0
    Views:
    113
    Chris
    Mar 18, 2006
  4. kj
    Replies:
    4
    Views:
    103
    Ilya Zakharevich
    Feb 5, 2006
  5. kj
    Replies:
    0
    Views:
    104
Loading...

Share This Page