C++ Won
7/8/2025, 12:12:16 AM No.105831578
This is what modern C++23 looks like:
std::pair<int, double> getTwoReturnValues() {
int value1 = 32;
double value2 = 3.14;
return {value1, value2};
}
void executeThisF(std::invocable<int> auto f) {
std::print("{}\n", f(3));
}
std::expected<int, std::string> parseInt(std::string_view s) {
try {
return std::stoi(std::string(s));
} catch (const std::exception& e) {
return std::unexpected("Failed to parse int: " + std::string(s));
}
}
int main() {
auto [a, b] = getTwoReturnValues();
std::print("a = {}, b = {}\n", a, b);
executeThisF([](int x) { return x * 3; });
std::unordered_map<std::string, int> config {
{"Alice", 90},
{"Bob", 85},
};
for (const auto& [k, v] : config) {
std::print("{} = {}\n", k, v);
}
std::vector<int> v = {1, 2, 3, 4, 5};
auto results = v | std::views::filter([](int n) { return n % 2 == 0; });
for (const auto& n : results) {
std::print("{}\n", n);
}
std::string input = "42";
if (auto result = parse_int(input); result) {
std::print("Parsed int: {}\n", result.value());
} else {
std::print("Error: {}\n", result.error());
}
}
When full support for C++ modules lands on Clang and CMake, it's going to be over for rustranny, if you fell for rustroon meme and went troon, there's still time to turn back.
std::pair<int, double> getTwoReturnValues() {
int value1 = 32;
double value2 = 3.14;
return {value1, value2};
}
void executeThisF(std::invocable<int> auto f) {
std::print("{}\n", f(3));
}
std::expected<int, std::string> parseInt(std::string_view s) {
try {
return std::stoi(std::string(s));
} catch (const std::exception& e) {
return std::unexpected("Failed to parse int: " + std::string(s));
}
}
int main() {
auto [a, b] = getTwoReturnValues();
std::print("a = {}, b = {}\n", a, b);
executeThisF([](int x) { return x * 3; });
std::unordered_map<std::string, int> config {
{"Alice", 90},
{"Bob", 85},
};
for (const auto& [k, v] : config) {
std::print("{} = {}\n", k, v);
}
std::vector<int> v = {1, 2, 3, 4, 5};
auto results = v | std::views::filter([](int n) { return n % 2 == 0; });
for (const auto& n : results) {
std::print("{}\n", n);
}
std::string input = "42";
if (auto result = parse_int(input); result) {
std::print("Parsed int: {}\n", result.value());
} else {
std::print("Error: {}\n", result.error());
}
}
When full support for C++ modules lands on Clang and CMake, it's going to be over for rustranny, if you fell for rustroon meme and went troon, there's still time to turn back.
Replies: