Last active
December 29, 2018 09:54
-
-
Save asford/b87d2f67115989692210a5690f7c6ec3 to your computer and use it in GitHub Desktop.
C++17 Tuple Operator Overloads
This file contains hidden or 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
// Fold expressions from https://medium.com/@matt.aubury/rip-index-sequence-2014-2017-9cc854aaad0 | |
` | |
template <typename... Ts, typename... Us> | |
auto operator+( | |
const std::tuple<Ts...> &tuple_t, const std::tuple<Us...> &tuple_u) { | |
return std::apply( | |
[&](const auto &... ts) { | |
return std::apply( | |
[&](const auto &... us) { return std::tuple(ts + us...); }, | |
tuple_u); | |
}, | |
tuple_t); | |
} | |
template <typename... Ts, typename... Us> | |
auto operator+=(std::tuple<Ts...> &tuple_t, const std::tuple<Us...> &tuple_u) { | |
return std::apply( | |
[&](auto &... ts) { | |
return std::apply( | |
[&](const auto &... us) { ((ts += us), ...); }, tuple_u); | |
}, | |
tuple_t); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment