Is it possible that the SFINAE test might fail, although the value of the expression (arg) is valid?
S: , .
() :
#include<type_traits>
template< typename T >
struct S {
template< typename U
, typename = std::enable_if_t<std::is_constructible< T, U >::value >
> explicit S (U&& arg) : value{arg} {}
T value;
};
struct A {};
struct B {
B(A &) {}
};
int main() {
S<B> s(A{});
}
, , :
, typename = std::enable_if_t<std::is_constructible< T, U >::value >
, . lvalue rvalue A ( arg) value.
B rvalue A, sfinae (), , sfinae, .
, B lvalue A, , , value{arg}.
S :
#include<utility>
template< typename T >
struct S {
template< typename U
, typename = std::enable_if_t<std::is_constructible< T, U >::value >
> explicit S (U&& arg) : value (std::forward<U>(arg)) { }
T value;
};
std::forward .
, , , , .