/* Copyright (c) 2018-2025 Marcelo Zimbres Silva (mzimbres@gmail.com) * * Distributed under the Boost Software License, Version 1.0. (See * accompanying file LICENSE.txt) */ #ifndef BOOST_REDIS_ADAPTER_DETAIL_RESPONSE_TRAITS_HPP #define BOOST_REDIS_ADAPTER_DETAIL_RESPONSE_TRAITS_HPP #include #include #include #include #include #include #include #include #include #include namespace boost::redis::adapter::detail { template class static_adapter { private: static constexpr auto size = std::tuple_size::value; using adapter_tuple = mp11::mp_transform; using variant_type = mp11::mp_rename; using adapters_array_type = std::array; adapters_array_type adapters_; std::size_t i_ = 0; public: explicit static_adapter(Response& r) { assigner::assign(adapters_, r); } void on_init() { using std::visit; visit( [&](auto& arg) { arg.on_init(); }, adapters_.at(i_)); } void on_done() { using std::visit; visit( [&](auto& arg) { arg.on_done(); }, adapters_.at(i_)); i_ += 1; } template void on_node(resp3::basic_node const& nd, system::error_code& ec) { using std::visit; // I am usure whether this should be an error or an assertion. BOOST_ASSERT(i_ < adapters_.size()); visit( [&](auto& arg) { arg.on_node(nd, ec); }, adapters_.at(i_)); } }; template struct response_traits; template <> struct response_traits { using response_type = ignore_t; using adapter_type = ignore; static auto adapt(response_type&) noexcept { return ignore{}; } }; template <> struct response_traits> { using response_type = result; using adapter_type = ignore; static auto adapt(response_type&) noexcept { return ignore{}; } }; template struct response_traits, Allocator>>> { using response_type = result, Allocator>>; using adapter_type = general_aggregate; static auto adapt(response_type& v) noexcept { return adapter_type{&v}; } }; template struct response_traits> { using response_type = response; using adapter_type = static_adapter; static auto adapt(response_type& r) noexcept { return adapter_type{r}; } }; } // namespace boost::redis::adapter::detail #endif // BOOST_REDIS_ADAPTER_DETAIL_RESPONSE_TRAITS_HPP