// // Copyright (c) 2019-2025 Ruben Perez Hidalgo (rubenperez038 at gmail dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_MYSQL_DETAIL_SEQUENCE_HPP #define BOOST_MYSQL_DETAIL_SEQUENCE_HPP #include #include #include #include #include #include #include #include #ifdef BOOST_MYSQL_HAS_CONCEPTS #include #endif namespace boost { namespace mysql { namespace detail { template struct sequence_range_impl { using type = T; }; template struct sequence_range_impl> { using type = T&; }; template struct sequence_range_impl { using type = std::array; }; template using sequence_range_type = sequence_range_impl>; template Range&& cast_range(Range&& range) { return std::forward(range); } template std::array, N> cast_range(T (&a)[N]) { return compat::to_array(a); } template std::array, N> cast_range(T (&&a)[N]) { return compat::to_array(std::move(a)); } // TODO: should this be Range&&? template void do_format_sequence(Range& range, const FormatFn& fn, constant_string_view glue, format_context_base& ctx) { bool is_first = true; for (auto it = std::begin(range); it != std::end(range); ++it) { if (!is_first) ctx.append_raw(glue); is_first = false; fn(*it, ctx); } } #ifdef BOOST_MYSQL_HAS_CONCEPTS template concept format_fn_for_range = requires(const FormatFn& format_fn, Range&& range, format_context_base& ctx) { { std::begin(range) != std::end(range) } -> std::convertible_to; format_fn(*std::begin(range), ctx); std::end(range); }; #endif } // namespace detail } // namespace mysql } // namespace boost #endif