Skip to content

is_mixin type trait #8

@psalvaggio

Description

@psalvaggio

I was working with the approach from this library and I found the following type trait to be useful. It might be worth including in your library if you agree:

template <typename T>
struct is_mixin {
 private:
  template <template <class> class... Mixins>
  static decltype(
      static_cast<const mixin<T, Mixins...>>(std::declval<T>()),
      std::true_type{})
  test(const mixin<T, Mixins...>&);
 
  static std::false_type test(...);
  
 public:
  static constexpr bool value =
      decltype(is_mixin::test(std::declval<T>()))::value;
};
  
template <typename T>
inline constexpr bool is_mixin_v = is_mixin<T>::value;

Usage:

template <typename Base>
struct A {
  CIABATTA_DEFAULT_MIXIN_CTOR(A, Base);
  int foo;
};
struct B : ciabatta::mixin<B, A> {};

static_assert(is_mixin_v<B>);
static_assert(!is_mixin_v<A>);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions