In the C++ Core Guidelines std::optional is only referred once:
If you need the notion of an optional value, use a pointer, std::optional, or a special value used to denote “no value.”
Other than that, it is not mentioned in the guidelines, so in particular there is no recommendation to use it instead of a pointer, when expressing the intent of an optional value.
Are there any disadvantages of the usage of std::optional in comparison to a pointer that might be null in a non-polymorphic context?
So std::optional is only referred as a side note and as the second option to a pointer.
To me it seems like that std::optional is much more expressive. When using a pointer, you can never be really sure if the option of a nullptr is intended.
std::optional.std::optionalbeing mentioned?std::optionalnot recommended" It is recommendingstd::optionalstd::optionaldoes not dynamically allocate the stored object. Whether this is an advantage or disadvantage depends, but it is not equivalent to passing a pointer. Suppose you have a function like this:void foo(SomeCustomTypeThatIsExpensiveToCopy *);. You wouldnt refactor this to usestd::optional(at least not without also doing heavy refactoring on the calling code)