mardi 28 avril 2015

Can I disable copy construction of a class based on the properties of it's template parameters? [duplicate]

This question already has an answer here:

A variant is the obvious example for this:

template <typename... Ts>
class variant {
  using types = meta::list<Ts...>;

  variant() = default;

  template <typename = std::enable_if_t<
    meta::all_of<types, meta::quote<std::is_copy_constructible>>{}
  >
  variant(const variant &);
};

Using Meta to remove TMP boilerplate code around checking to see if all of a parameter pack fulfil a trait.

I know this isn't correct as the copy constructor can't be templated amongst other restrictions. Is this something that is possible to do in a different manner? C++14+ should be fine as I'm using GCC 4.9 and Clang 3.5.

Aucun commentaire:

Enregistrer un commentaire