arg_router  1.4.0
C++ command line argument parsing and routing
tuple_iterator.hpp
1 // Copyright (C) 2022-2023 by Camden Mannett.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
4 
5 #pragma once
6 
7 #include "arg_router/traits.hpp"
8 
9 #include <boost/mp11/algorithm.hpp>
10 
13 namespace arg_router::utility
14 {
32 template <typename F, typename Tuple>
33 constexpr std::enable_if_t<traits::is_tuple_like_v<std::decay_t<Tuple>>> tuple_iterator(
34  F&& f,
35  Tuple&& tuple)
36 {
37  constexpr auto N = std::tuple_size_v<std::decay_t<Tuple>>;
38  boost::mp11::mp_for_each<boost::mp11::mp_iota_c<N>>([&](auto i) { f(i, std::get<i>(tuple)); });
39 }
40 
49 template <typename F, typename... T>
50 constexpr void tuple_iterator(F&& f, T&&... pack)
51 {
52  tuple_iterator(std::forward<F>(f), std::tuple{std::forward<T>(pack)...});
53 }
54 
74 template <typename Tuple, typename F>
75 constexpr std::enable_if_t<traits::is_tuple_like_v<std::decay_t<Tuple>>> tuple_type_iterator(F&& f)
76 {
77  constexpr auto N = std::tuple_size_v<std::decay_t<Tuple>>;
78  boost::mp11::mp_for_each<boost::mp11::mp_iota_c<N>>([&](auto i) { f(i); });
79 }
80 } // namespace arg_router::utility
constexpr std::enable_if_t< traits::is_tuple_like_v< std::decay_t< Tuple > > > tuple_iterator(F &&f, Tuple &&tuple)
constexpr std::enable_if_t< traits::is_tuple_like_v< std::decay_t< Tuple > > > tuple_type_iterator(F &&f)