Skip to content

Commit 6315171

Browse files
committed
Add tuple application utility and size retrieval in fast_io_dsal
- Introduced `apply` function to facilitate the application of a callable to elements of a tuple. - Added `tuple_size` function to retrieve the size of a `fast_io::containers::tuple`. - Implemented helper functions in the `details` namespace for improved code organization and clarity.
1 parent 0e8e82d commit 6315171

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

include/fast_io_dsal/impl/tuple.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,32 @@ FAST_IO_GNU_ALWAYS_INLINE
182182
static_cast<decltype(::fast_io::containers::details::get_tuple_element_by_type_<T, 0, Args...>())::type const &&>(self).val_);
183183
}
184184

185+
namespace details
186+
{
187+
template <typename F, typename Tuple, std::size_t... I>
188+
inline constexpr decltype(auto) apply_impl(F &&f, Tuple &&t, ::std::index_sequence<I...>)
189+
{
190+
return ::std::forward<F>(f)(get<I>(::std::forward<Tuple>(t))...);
191+
}
192+
193+
template <typename... Args>
194+
inline consteval ::std::size_t tuple_size(::fast_io::containers::tuple<Args...> const &) noexcept
195+
{
196+
return sizeof...(Args);
197+
}
198+
199+
} // namespace details
200+
201+
template <typename F, typename Tuple>
202+
inline constexpr decltype(auto) apply(F &&f, Tuple &&t)
203+
{
204+
constexpr ::std::size_t N{details::tuple_size(t)};
205+
return details::apply_impl(
206+
::std::forward<F>(f),
207+
::std::forward<Tuple>(t),
208+
::std::make_index_sequence<N>{});
209+
}
210+
185211
namespace details
186212
{
187213

0 commit comments

Comments
 (0)