I’m trying to see if an object of type T
can be constructed with an argument of type U
.
You’d think std::is_constructible
would be close enough (aside from the fact that it also checks destructability, which I would’ve ideally liked to avoid), but apparently this fails:
#include <type_traits>
using U = int;
enum T : U { };
static_assert(std::is_constructible<T, U>::value, "error"); // fails
static_assert(std::is_convertible<U, T>::value, "error"); // fails
I guess that makes sense, since T e((U()))
fails, but that’s not what I’m looking for because auto v = T(U())
and auto v = static_cast<T>(U())
both succeed.
This also makes me wonder what other edge cases I may have missed… I have no idea.
What’s the right way to test solely constructability via the T(...)
syntax, ideally using standard traits, with as few false-positives or false-negatives as possible?