std::get
does not seem to be SFINAE-friendly, as shown by the following test case:
template
auto foo(C &c) -> declty
Don't SFINAE on std::get
; that is not permitted.
Here are two relatively sfinae friendly ways to test if you can using std::get; get
:
template
using can_get=std::integral_constant::value>;
namespace helper{
template
struct can_get_type:std::false_type{};
template
struct can_get_type>:
std::integral_constant+...)==1>
{};
}
template
using can_get=typename helpers::can_get_type::type;
Then your code reads:
template {},int> =0>
decltype(auto) foo(C &c) {
return std::get(c);
}