are there any other voidt replacements in c20?

You can use the detected idiom, which is an abstraction over void_t. This is pretty much the closest you can get from concepts without them:

template <typename Default, typename AlwaysVoid, template<typename...> typename Op, typename... Args>
struct detector {
    using value_t = std::false_type;
    using type = Default;
};

template <typename Default, template<typename...> typename Op, typename... Args>
struct detector<Default, std::void_t<Op<Args...>>, Op, Args...> {
    using value_t = std::true_type;
    using type = Op<Args...>;
};

template <template<typename...> typename Op, typename... Args>
using is_detected = typename detail::detection::detector<nonesuch, void, Op, Args...>::value_t;

template <template<typename...> typename Op, typename... Args>
constexpr auto is_detected_v = detail::detection::detector<nonesuch, void, Op, Args...>::value_t::value;

template <template<typename...> typename Op, typename... Args>
using detected_t = typename detail::detection::detector<nonesuch, void, Op, Args...>::type;

template <typename Default, template<typename...> typename Op, typename... Args>
using detected_or = typename detail::detection::detector<Default, void, Op, Args...>::type;

It can then be used like this:

template<typename A, typename B, typename C>
using my_is_constructible_expr = decltype(A(std::declval<B>(), std::declval<C>()));

// Trait type that has ::value
template<typename A, typename B, typename C>
using my_is_constructible = is_detected<my_is_constructible_expr, A, B, C>;

// template variable, even closer to concepts
template<typename A, typename B, typename C>
inline constexpr bool my_is_constructible_v = is_detected_v<my_is_constructible_expr, A, B, C>;

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top