This is a simple game I'm writing to test the idea of using games to teach C++.
https://learncodethehardway.com/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
497 B
31 lines
497 B
#include <iostream>
|
|
#include <optional>
|
|
#include <string>
|
|
|
|
using namespace std;
|
|
|
|
optional<string> create(bool b)
|
|
{
|
|
if(b) {
|
|
return "Godzilla";
|
|
} else {
|
|
return {};
|
|
}
|
|
}
|
|
|
|
auto create2(bool b)
|
|
{
|
|
return b ? optional<string>{"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;
|
|
}
|
|
|