24 lines
449 B
C++
24 lines
449 B
C++
#include <optional>
|
|
#include <iostream>
|
|
|
|
std::optional<int> my_div(int a, int b) {
|
|
if (b == 0) {
|
|
return {};
|
|
}
|
|
//return std::make_optional<int>(a / b);
|
|
return {a / b};
|
|
}
|
|
|
|
int main() {
|
|
auto opt = my_div(16, 0);
|
|
//if (opt.has_value()) {
|
|
if (opt) {
|
|
std::cout << "Correct!\n";
|
|
//std::cout << opt.value() << '\n';
|
|
std::cout << *opt << '\n';
|
|
} else {
|
|
std::cout << "Incorrect!\n";
|
|
// To jest terroryzm!
|
|
std::cout << *opt << '\n';
|
|
}
|
|
}
|