Skip to content

Instantly share code, notes, and snippets.

@jeremy-rifkin
Last active August 8, 2021 02:33
Show Gist options
  • Save jeremy-rifkin/77eb6ad9f4ab387bb1e1a1e1c34c89ac to your computer and use it in GitHub Desktop.
Save jeremy-rifkin/77eb6ad9f4ab387bb1e1a1e1c34c89ac to your computer and use it in GitHub Desktop.
Very simple idiomatic C++ program to add two numbers together
#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