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

A

Alf P. Steinbach

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top