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.
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.
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).