Is it possible to implement always_false in the C++ standard library?

后端 未结 3 1773
野的像风
野的像风 2021-02-07 09:10

There are cases where one uses an always_false helper to e.g. cause unconditional static_assert failure if instantiation of some template is attempted:

3条回答
  •  情书的邮戳
    2021-02-07 09:42

    In C++20, with lambda, you might do something like:

    template  struct always_false : std::false_type {};
    
    // To have true, but for a type that user code can't reuse as lambda types are unique.
    template <> struct always_false : std::true_type{};
    

提交回复
热议问题