Search code examples
c++14template-meta-programmingtype-traitsdecltypeenable-if

Counterpart to std::enable_if_t


std::enable_if_t gets you a type if a certain value is true. Now I want a thing that gets you a type if an expression is well-formed. If the type I want is void, I can do decltype((void)(expr)). But what should I do if I want something other than void? I want an succinct and elegant solution.


Solution

  • You can use something like this:

    template<typename T>
    struct well_formed : std::true_type{};
    

    And then combine that with enable_if_t