From: Adam C. Emerson Date: Wed, 10 Jan 2018 04:26:48 +0000 (-0500) Subject: common: Add ceph::for_each for tuples X-Git-Tag: v13.0.2~525^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=abd4c104f8aaa1b8cc233ad8a4dd08155874cf79;p=ceph.git common: Add ceph::for_each for tuples Expand to pairs, optionals, and variants later. Signed-off-by: Adam C. Emerson --- diff --git a/src/common/convenience.h b/src/common/convenience.h index c28349382095..3989c70d1043 100644 --- a/src/common/convenience.h +++ b/src/common/convenience.h @@ -229,5 +229,45 @@ auto maybe_do_or(const std::optional& t, F&& f, U&& u) -> else return std::forward(u); } + +namespace _convenience { +template +inline void for_each_helper(const std::tuple& t, const F& f, + std::index_sequence) { + (f(std::get(t)), ..., void()); +} +template +inline void for_each_helper(std::tuple& t, const F& f, + std::index_sequence) { + (f(std::get(t)), ..., void()); +} +template +inline void for_each_helper(const std::tuple& t, F& f, + std::index_sequence) { + (f(std::get(t)), ..., void()); +} +template +inline void for_each_helper(std::tuple& t, F& f, + std::index_sequence) { + (f(std::get(t)), ..., void()); +} +} + +template +inline void for_each(const std::tuple& t, const F& f) { + _convenience::for_each_helper(t, f, std::index_sequence_for{}); +} +template +inline void for_each(std::tuple& t, const F& f) { + _convenience::for_each_helper(t, f, std::index_sequence_for{}); +} +template +inline void for_each(const std::tuple& t, F& f) { + _convenience::for_each_helper(t, f, std::index_sequence_for{}); +} +template +inline void for_each(std::tuple& t, F& f) { + _convenience::for_each_helper(t, f, std::index_sequence_for{}); +} } #endif // CEPH_COMMON_CONVENIENCE_H