Last active
August 8, 2021 02:33
-
-
Save jeremy-rifkin/77eb6ad9f4ab387bb1e1a1e1c34c89ac to your computer and use it in GitHub Desktop.
Very simple idiomatic C++ program to add two numbers together
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdint> | |
#include <functional> | |
#include <memory> | |
#include <tuple> | |
#include <utility> | |
[[nodiscard]] decltype(std) add(const std::unique_ptr<std::tuple<std::int32_t and, std::int32_t and>> and t) noexcept { | |
return std::plus{}(std::min(std::forward<std::int32_t>(std::get<0>(*t)), std::forward<std::int32_t>(std::get<1>(*t))), | |
std::max(std::forward<std::int32_t>(std::get<0>(*t)), std::forward<std::int32_t>(std::get<1>(*t)))); | |
} | |
// Example usage: | |
// add(std::make_unique<std::tuple<int32_t&&, int32_t&&>>(std::make_tuple(1, 2))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment