File indexing completed on 2025-01-18 09:12:13
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include <tuple>
0012 #include <type_traits>
0013 #include <utility>
0014
0015 namespace ActsFatras::detail {
0016
0017
0018 template <bool Initial, typename Combine, typename... Selectors>
0019 class CombineSelectors {
0020 static_assert(0u < sizeof...(Selectors),
0021 "Must combine at least one selector");
0022
0023 public:
0024
0025
0026
0027
0028
0029
0030 template <typename... Ts>
0031 bool operator()(const Ts &...things) const {
0032 static_assert(
0033 (true && ... && std::is_same_v<bool, decltype(Selectors()(things...))>),
0034 "Not all selectors conform to the expected interface (bool)(const "
0035 "T&...)");
0036 return impl(std::index_sequence_for<Selectors...>(), things...);
0037 }
0038
0039
0040 template <std::size_t I>
0041 std::tuple_element_t<I, std::tuple<Selectors...>> &get() {
0042 return std::get<I>(m_selectors);
0043 }
0044
0045 template <typename Selector>
0046 Selector &get() {
0047 return std::get<Selector>(m_selectors);
0048 }
0049
0050 private:
0051 std::tuple<Selectors...> m_selectors;
0052
0053 template <std::size_t... Is, typename... Ts>
0054 bool impl(std::index_sequence<Is...> , const Ts &...things) const {
0055 Combine combine;
0056
0057 bool status[] = {std::get<Is>(m_selectors)(things...)...};
0058
0059 bool ret = Initial;
0060 for (bool value : status) {
0061 ret = combine(ret, value);
0062 }
0063 return ret;
0064 }
0065 };
0066
0067 }