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

后端 未结 3 1776
野的像风
野的像风 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:54

    To paraphrase Jarod's idea, It could be something like

    template  struct always_false : std::false_type {};
    
    template <> struct always_false : std::true_type{};
    

    Where /* implementation defined */ can be filled by std::_ReservedIdentifer. User code can't access it, since the identifier is reserved to the library, but there exists a specialization that is true. That should avoid questions about the ODR and lambdas in specializations.

提交回复
热议问题