Please consider the following code snippet:
template<class E>
class vector_expression {};
template<class Tuple>
class vector
: public vector_expression<vector<Tuple>>
{
public:
using value_type = typename Tuple::value_type;
};
template<typename T>
using dynamic_vector = vector<std::vector<T>>;
namespace detail
{
template<class E>
constexpr bool is_vector_expression_v = std::is_base_of_v<vector_expression<std::decay_t<E>>, std::decay_t<E>>;
template<class E>
struct value_type { using type = std::decay_t<E>; };
template<class E>
struct value_type<vector_expression<std::decay_t<E>>> { using type = typename std::decay_t<E>::value_type; };
template<class E>
using value_type_t = typename value_type<E>::type;
}
int main()
{
static_assert(std::is_same<detail::value_type_t<dynamic_vector<double>>, double>::value, "not the same");
return 0;
}
I want value_type_t<E>
to be the value_type
specified in E
whenever E
is a vector_expression
. The code above is not working, cause the template parameter E
is not deducible in the partial specialization of value_type
. How can I make the code work?