I\'m using SFINAE in the style of this answer in order to call a generic vector object by using an appropriate member function. For example, the following code calls o
Or you can just use tag-dispatching:
auto get(int i) const
{
return get(i, has_bracket_operator(), has_parenthesis_operator());
}
auto get(int i, std::true_type /*brackets*/, std::false_type /*parenthesis*/) const
{
return v[i];
}
auto get(int i, std::false_type /*brackets*/, std::true_type /*parenthesis*/) const
{
return v(i);
}
demo