std::optional – construct empty with {} or std::nullopt?

In this case, {} invokes value-initialization. If optional‘s default constructor is not user-provided (where “not user-provided” means roughly “is implicitly declared or explicitly defaulted within the class definition”), that incurs zero-initialization of the entire object.

Whether it does so depends on the implementation details of that particular std::optional implementation. It looks like libstdc++’s optional‘s default constructor is not user-provided, but libc++’s is.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)