I am trying to make a function X that specializes when a member function Y is provided, and if a member function Y is not provided, the function X uses the global non-member function Y to achieve the same effect.
I am currently trying to achieve this with the following code
template <typename Container, typename std::enable_if_t<std::is_same<
decltype(std::declval<Container>().y()),
decltype(std::declval<Container>().y())>::value>* = nullptr>
void do_something(Container&& container) {
return std::forward<Container>().y();
}
template <typename Container, typename std::enable_if_t<!std::is_same<
decltype(std::declval<Container>().y()),
decltype(std::declval<Container>().y())>::value>* = nullptr>
void do_something(Container&& container) {
return y(std::forward<Container>(container);
}
But in the case when the container has both a member function y and a global non-member function y. Compilation error, because for the second version of the function, the template argument is poorly formed, because the member function y is needed.
Any idea how I can solve this problem?
. , . , , , ! .