mirror of
https://github.com/matrix-construct/construct
synced 2025-01-01 02:14:13 +01:00
ircd::util: Add non-const overloads to tuple iterations.
This commit is contained in:
parent
5a7852a0d4
commit
c8953c038d
1 changed files with 39 additions and 0 deletions
|
@ -125,6 +125,14 @@ using custom_ptr = std::unique_ptr<T, std::function<void (T *) noexcept>>;
|
||||||
//
|
//
|
||||||
// for_each(tuple, [](auto&& elem) { ... });
|
// for_each(tuple, [](auto&& elem) { ... });
|
||||||
|
|
||||||
|
template<size_t i,
|
||||||
|
class func,
|
||||||
|
class... args>
|
||||||
|
typename std::enable_if<i == std::tuple_size<std::tuple<args...>>::value, void>::type
|
||||||
|
for_each(std::tuple<args...> &t,
|
||||||
|
func&& f)
|
||||||
|
{}
|
||||||
|
|
||||||
template<size_t i,
|
template<size_t i,
|
||||||
class func,
|
class func,
|
||||||
class... args>
|
class... args>
|
||||||
|
@ -144,11 +152,32 @@ for_each(const std::tuple<args...> &t,
|
||||||
for_each<i+1>(t, std::forward<func>(f));
|
for_each<i+1>(t, std::forward<func>(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<size_t i = 0,
|
||||||
|
class func,
|
||||||
|
class... args>
|
||||||
|
typename std::enable_if<i < std::tuple_size<std::tuple<args...>>::value, void>::type
|
||||||
|
for_each(std::tuple<args...> &t,
|
||||||
|
func&& f)
|
||||||
|
{
|
||||||
|
f(std::get<i>(t));
|
||||||
|
for_each<i+1>(t, std::forward<func>(f));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Iteration of a tuple until() style: your closure returns true to continue, false
|
// Iteration of a tuple until() style: your closure returns true to continue, false
|
||||||
// to break. until() then remains true to the end, or returns false if not.
|
// to break. until() then remains true to the end, or returns false if not.
|
||||||
|
|
||||||
|
template<size_t i,
|
||||||
|
class func,
|
||||||
|
class... args>
|
||||||
|
typename std::enable_if<i == std::tuple_size<std::tuple<args...>>::value, bool>::type
|
||||||
|
until(std::tuple<args...> &t,
|
||||||
|
func&& f)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
template<size_t i,
|
template<size_t i,
|
||||||
class func,
|
class func,
|
||||||
class... args>
|
class... args>
|
||||||
|
@ -159,6 +188,16 @@ until(const std::tuple<args...> &t,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<size_t i = 0,
|
||||||
|
class func,
|
||||||
|
class... args>
|
||||||
|
typename std::enable_if<i < std::tuple_size<std::tuple<args...>>::value, bool>::type
|
||||||
|
until(std::tuple<args...> &t,
|
||||||
|
func&& f)
|
||||||
|
{
|
||||||
|
return f(std::get<i>(t))? until<i+1>(t, std::forward<func>(f)) : false;
|
||||||
|
}
|
||||||
|
|
||||||
template<size_t i = 0,
|
template<size_t i = 0,
|
||||||
class func,
|
class func,
|
||||||
class... args>
|
class... args>
|
||||||
|
|
Loading…
Reference in a new issue