diff --git a/PPP3/ex08.cpp b/PPP3/ex08.cpp index e467e6d..1dc5827 100644 --- a/PPP3/ex08.cpp +++ b/PPP3/ex08.cpp @@ -1,8 +1,31 @@ #include +#include +#include using namespace std; +optional create(bool b) +{ + if(b) { + return "Godzilla"; + } else { + return {}; + } +} + +auto create2(bool b) +{ + return b ? optional{"Godzilla"} : nullopt; +} + int main() { + cout << "create(false) returned " + << create(false).value_or("empty") << "\n"; + + if(auto str = create2(true)) { + cout << "create2(true) returned " << *str << " with size " << str->size() << "\n"; + } + return 0; }