jeudi 6 avril 2017

std::conditional with SFINAE

Is it possible to create a sort of std::enable_if_and_else, like std::conditional but without the compile time errors for classes that are not defined.

Here is an example:

static constexpr bool myExpr = true;

struct A {};
struct B;

struct C :
    std::conditional<myExpr,
      A,
      B>::type
    {};  // Compilation error: B is declared but not defined

struct D :
    enable_if_else<myExpr,
      A,
      B>::type
    {};  // It works

Thanks

Aucun commentaire:

Enregistrer un commentaire