GuillaumeDua / CppShelf

Collection of powerfuls - C++ Single-Header Libraries Files
https://guillaumedua.github.io/CppShelf/
MIT License
9 stars 1 forks source link

[mp] compose #176

Open GuillaumeDua opened 7 months ago

GuillaumeDua commented 7 months ago

See implementation here


Usage:

template <typename T>
using not_convertible_to_int = csl::mp::compose<
    std::negation,
    csl::mp::bind_back<std::is_convertible, int>::type
>::type<T>;

template <typename T>
constexpr auto not_convertible_to_int_v = not_convertible_to_int<T>::value;

// ---

struct A{};
struct B{ operator int(){ return 42; } };

static_assert(    not_convertible_to_int_v<A>);
static_assert(not not_convertible_to_int_v<B>);

Details:

// compose (TODO: remove recursivity ¯\_(ツ)_/¯)
template <template <typename...> typename ... traits>
struct compose;
template <template <typename...> typename traits>
struct compose<traits> {
    template <typename ... Ts>
    using type = typename traits<Ts...>::type;
};
template <
    template <typename...> typename trait,
    template <typename...> typename ... rest
>
struct compose<trait, rest...> {
    template <typename ... Ts>
    using type = trait<typename compose<rest...>::template type<Ts...>>;
};