[cfe-dev] a question on __invoke
mclow.lists at gmail.com
Thu Jul 10 09:12:48 PDT 2014
On Jul 9, 2014, at 3:41 AM, 苏焕然 <ownesss at gmail.com> wrote:
> I don't quite understand about __invoke bullet2 and bullet4.
> for example, bullet2:
> template <class _Fp, class _A0, class ..._Args,
> class = typename enable_if
> is_member_function_pointer<typename remove_reference<_Fp>::type>::value &&
> !is_base_of<typename remove_reference<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType>::type,
> typename remove_reference<_A0>::type>::value
> __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
> -> decltype(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...));
> this functions invokes f with (*a0).f(args) (as written in header __functional_base), so I guess that a0/A0 has the type of Pointer to Class? (thus, of course, isn't a base class of himself)
> Then why did enable_if just test if ClassType of f isn't a base class of A0 ?
> && is_base_of<member_pointer_traits<_Fp>::ClassType, remove_pointer<A0>>::value
> be more accurate? also, wouldn't <Some_Class_C::*Fp, Some_Class_D, Some_Args...> makes the value of enable_if to be true?
> I must guess that there is something I hadn't taken into consideration ;>
The enable_if conditions are taken directly from the description in the standard (using N3936 here), 20.9.2/1:
Define INVOKE (f, t1, t2, ..., tN) as follows:
— (t1.*f)(t2, ..., tN) when f is a pointer to a member function of a class T and t1 is an object of
type T or a reference to an object of type T or a reference to an object of a type derived from T;
— ((*t1).*f)(t2, ..., tN) when f is a pointer to a member function of a class T and t1 is not one of
the types described in the previous item;
— Bullet #3 elided
— Bullet #4 elided
— Bullet #5 elided
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cfe-dev