Boost logo

Boost :

Subject: Re: [boost] [TypeTraits] propose new callable-type call traits
From: TONGARI J (tongari95_at_[hidden])
Date: 2014-01-11 14:55:23


Hi,

2014/1/12 Hui Li <hui.li_at_[hidden]>

> I've implemented a few traits classes (code attached below) that, for a
> given callable-type T, and a set of Args..., detects whether the function
> call T::operator()(Args...) would be
> (1) valid,
> (2) ambiguous, or
> (3) none is viable.
> where T is allowed to have arbitrary overloaded operator()'s.
>
> This could be useful for programmers who want to
> (1) make the function call only when it's valid,
> (2) generate customized error/warning messages when it's ambiguous, or
> handle/redirect it without getting an ambiguous compiler error, and
> (3) redirect non-viable calls to some default behavior, which can be
> different than how it's handled when the call is ambiguous.
>
> If people are interested, I suppose this could be a useful addition to
> TypeTraits.
> I would appreciate any feedback!
>
> For clarity, the implementation and demonstration attached below is
> written in c++11. It can be easily ported to c++98/03 compilers by using
> TypeTratis to replace the std type traits, BOOST_TYPEOF_KEYWORD to replace
> decltype, and Boost.Preprocessor to generate code for arbitrary arity.
>

It's interesting that you use ambiguity to distinguish the types.
Anyway, your code doesn't support function(pointer) which is also Callable,
and... are you sure your approach can be ported back to C++03 where there's
no SFINAE on expression?

FWIW, I have my has_call implementation:
https://github.com/jamboree/boost.has_call
which works for both C++11/03.

I have real world usage of has_call (or has_valid_call in yours), but I
don't have the need of has_ambiguous_call so far.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk