Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

29 views
Skip to first unread message

Alf P. Steinbach

unread,
Nov 11, 2013, 7:59:17 PM11/11/13
to
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
[/code]


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
0 new messages