in_place Construction
Here, we will discuss why it is a good practice to use in_place with std::optional.
We'll cover the following...
std::optional
is a wrapper type, so you should be able to create optional objects almost in the same way as the wrapped object. And in most cases you can:
Press + to interact
#include <iostream>#include <optional>using namespace std;int main() {std::optional<std::string> ostr{"Hello World"};std::optional<int> oi{10};cout << *ostr << endl;cout << *oi << endl;}
You ...