Boost logo

Boost :

Subject: [boost] [type_traits] has_member_function_callable_with
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2011-09-15 17:18:58


Hi to all,

Trying to port C++11 code (allocator_traits) to C++03 (without decltype
support), I needed to check at compile time if a member function can be
called with some given parameters.

Typical solutions I found on the net were based on specific signatures, say:

const bool value =
  HAS_MEMBER_FUNCTION_FUNCNAME_WITH_SIGNATURE(MyClass, (int, char*));

However, it is not feasible to know the exact signature as I want to
deal with conversions, const references, etc. Luckily, I found a very
interesting explanation in Proto documentation:

http://www.boost.org/doc/libs/1_47_0/doc/html/proto/appendices.html#boost_proto.appendices.implementation.function_arity

Based on this, I've tried to write my solution and I'd like to share it
here with type traits experts, in case someone knows a better solution
(see attached example). I know I don't take into account many issues for
a truly generic utility (const member functions, etc.) but please let me
know if you find this example interesting.

Best,

Ion




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