Basically I want to check if a templated type T<U, Args...> can be constructed from some other type T<V, Args...>. Where T and Args... is the same in both types. The problem is, T<> might have a static_assert in it that totally breaks my metafunction.
Below is a rough summary of what I'm trying to do.
template<typename T>
struct fake_alloc {
using value_type = T;
};
template<typename T, typename Alloc = fake_alloc<T>>
struct fake_cont {
using value_type = T;
static_assert(std::is_same<value_type, typename Alloc::value_type>::value, "must be the same type");
};
template<typename T, typename U, typename = void>
struct sample_rebind {
using type = T;
};
template<template<typename...> class Container, typename T, typename U, typename... OtherArgs>
struct sample_rebind<
Container<T, OtherArgs...>,
U,
std::enable_if_t<
std::is_constructible<
Container<T, OtherArgs...>,
Container<U, OtherArgs...>
>::value
>
>
{
using type = Container<U, OtherArgs...>;
};
static_assert(
std::is_same<
fake_cont<double, fake_alloc<int>>,
typename sample_rebind<fake_cont<int>, double>::type
>::value,
"This should pass!"
);
As you can see the desired behavior is that the final static_assert should pass, but unfortunately, it doesn't even get to that point as the static_assert in fake_cont is triggered when std::is_constructible<> attempts to call fake_cont's constructor.
In the real code fake_cont is libc++'s std::vector, so I can't modify it's guts, or std::is_constructible's guts.
Any advice for working around this specific issue is appreciated, and any advice in general for SFINAE'ing around static_assert's is especially appreciated.
Aucun commentaire:
Enregistrer un commentaire