What is the rationale for boost::none_t implementation?

后端 未结 1 599
自闭症患者
自闭症患者 2021-01-01 11:24

Boost.Optional uses a dummy type to allow constructing uninitialized instances of boost::optional. This type is called none_t, and an inst

相关标签:
1条回答
  • 2021-01-01 12:06

    Ah, I had never thought to dig deeper.

    One (more or less obvious) advantage to a regular struct, is that now none evaluates to false in boolean contexts.

    One advantage over another "evaluates to false" is that pointer to member are prevented from harmful promotion to integral types.

    So, I guess that it offers a safe and concise way of having a object that evaluates to false.

    EDIT: One should recognize here (hum...) the structure of the Safe Bool Idiom.

    0 讨论(0)
提交回复
热议问题