mardi 5 mai 2015

std::enable_if sfine custom type via template template parameter?

  1. Let say that I have custom struct like this one

    struct Var:{};

    struct is_var_type:std::integral_constant::type>::value > {};

After this, I want to have some custom type via template parameter sfine using std::enable_if, however I couldnt figure out. From what I could do was only following ways

  template<typename T> 
  void variant(T a)
  { 
  if (is_var_type<Var>::value){
   cout <<" "<<true;
   }
   else {
     cout <<" "<<false; 
    }

I want to make something like this one, but std::is_integral is already been defined. How to make custom one ?

   template<class T ,
      typename std::enable_if<std::is_integral<T>::value>::type* = nullptr >
     T foo3(T t) // note, function signature is unmodified
    {
      return t;
    }
    }

  1. Does this way is possible if we add some container type like

    struct Var:{}; struct ListVar:public std::list struct is_var_type: std::integral_constant::type>::value > {};

But I got compile time error, cannot deduce multiple type in gcc 4.9.

Aucun commentaire:

Enregistrer un commentaire