std::optional - construct empty with {} or std::nullopt?
问题 I thought that initializing a std::optional with std::nullopt would be the same as default construction. They are described as the same at cppreference, as form (1) However, both Clang and GCC seem to treat these toy example functions differently. #include <optional> struct Data { char large_data[0x10000]; }; std::optional<Data> nullopt_init() { return std::nullopt; } std::optional<Data> default_init() { return {}; } Compiler Explorer seems to imply that using std::nullopt will simply set the