I'm writing a wrapper class for a class of type inner_t. Can I call the proper constructor (lvalue reference or rvalue reference) for the inner class in the following way?
template<typename S, typename T>
struct u_ref {
};
template<typename S>
struct u_ref<S, const S&> {
typedef const S& type;
};
template<typename S>
struct u_ref<S, S&&> {
typedef S&& type;
};
class wrapper_t {
private:
inner_t data;
public:
template<typename T>
wrapper_t(typename u_ref<inner_t,T>::type c_data):
data(std::forward(c_data)) {
}
}
The standard idiom is this:
Baby's first template:
Grown-up version: The problem with the above is that it makes
Foo
constructible from anything, which is unclean. We must disable overloads that don't make sense.In this manner, the trait
std::is_constructible<Foo, Args...>
will have the exact same values asstd::constructible<Inner, Args...>
, rather than being true for everything.