views:

480

answers:

1

hi

Is it possible to use boost type traits or some other mechanism to check if a particular template parameter has an operator/function, e.g. std::vector as a template parameter has operator[], while std::pair does not.

+3  A: 

You can't solve this via type traits because you'd have to define if for every possible name.

Here are the common solutions listed, which have one problem though: many STL implementations put common code in base classes and this method doesn't check for inherited names.

If you need to check for inherited members too, see here. The answer provides a solution that checks wether the class in question has a member of that name and can also check for const-ness and argument count. It fails however to check for the full signature including argument and return types and member visibility doesn't make a difference. You should be able to solve that partially by using the linked is_call_possible<> (haven't had time yet too look at it).

Georg Fritzsche
Every time I see that `is_call_possible` thread, a little bit of me gets scared.
GMan
my Russian is paying off, thanks
aaa
@GMan: I'll have to take heart and attack that next month ;)
Georg Fritzsche