experimental::optional nullopt_t constructor

无人久伴 提交于 2019-12-05 07:03:31

A minimal implementation is

struct nullopt_t {
    constexpr nullopt_t(int) {}
};

No default constructor will be implicitly declared, [class.ctor]/4:

If there is no user-declared constructor for class X, a constructor having no parameters is implicitly declared as defaulted (8.4).

... and nullopt_t can be constructed from int, a literal type.
Note that in your code a default constructor exists, though being defined as deleted.

The above definition does meet the requirements for a literal type:

A type is a literal type if it is:
(10.5) — a class type (Clause 9) that has all of the following properties:

  • it has a trivial destructor,
  • it is an aggregate type (8.5.1) or has at least one constexpr constructor [..] that is not a copy or move constructor, and
  • all of its non-static data members and base classes are of non-volatile literal types.
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!