Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:39:15

0001 //
0002 // Copyright (c) 2019-2025 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 
0008 #ifndef BOOST_MYSQL_DETAIL_SEQUENCE_HPP
0009 #define BOOST_MYSQL_DETAIL_SEQUENCE_HPP
0010 
0011 #include <boost/mysql/constant_string_view.hpp>
0012 #include <boost/mysql/format_sql.hpp>
0013 
0014 #include <boost/compat/to_array.hpp>
0015 #include <boost/compat/type_traits.hpp>
0016 
0017 #include <array>
0018 #include <cstddef>
0019 #include <functional>
0020 #include <iterator>
0021 
0022 #ifdef BOOST_MYSQL_HAS_CONCEPTS
0023 #include <concepts>
0024 #endif
0025 
0026 namespace boost {
0027 namespace mysql {
0028 namespace detail {
0029 
0030 template <class T>
0031 struct sequence_range_impl
0032 {
0033     using type = T;
0034 };
0035 
0036 template <class T>
0037 struct sequence_range_impl<std::reference_wrapper<T>>
0038 {
0039     using type = T&;
0040 };
0041 
0042 template <class T, std::size_t N>
0043 struct sequence_range_impl<T[N]>
0044 {
0045     using type = std::array<T, N>;
0046 };
0047 
0048 template <class T>
0049 using sequence_range_type = sequence_range_impl<compat::remove_cvref_t<T>>;
0050 
0051 template <class Range>
0052 Range&& cast_range(Range&& range)
0053 {
0054     return std::forward<Range>(range);
0055 }
0056 
0057 template <class T, std::size_t N>
0058 std::array<compat::remove_cv_t<T>, N> cast_range(T (&a)[N])
0059 {
0060     return compat::to_array(a);
0061 }
0062 
0063 template <class T, std::size_t N>
0064 std::array<compat::remove_cv_t<T>, N> cast_range(T (&&a)[N])
0065 {
0066     return compat::to_array(std::move(a));
0067 }
0068 
0069 // TODO: should this be Range&&?
0070 template <class Range, class FormatFn>
0071 void do_format_sequence(Range& range, const FormatFn& fn, constant_string_view glue, format_context_base& ctx)
0072 {
0073     bool is_first = true;
0074     for (auto it = std::begin(range); it != std::end(range); ++it)
0075     {
0076         if (!is_first)
0077             ctx.append_raw(glue);
0078         is_first = false;
0079         fn(*it, ctx);
0080     }
0081 }
0082 
0083 #ifdef BOOST_MYSQL_HAS_CONCEPTS
0084 template <class FormatFn, class Range>
0085 concept format_fn_for_range = requires(const FormatFn& format_fn, Range&& range, format_context_base& ctx) {
0086     { std::begin(range) != std::end(range) } -> std::convertible_to<bool>;
0087     format_fn(*std::begin(range), ctx);
0088     std::end(range);
0089 };
0090 #endif
0091 
0092 }  // namespace detail
0093 }  // namespace mysql
0094 }  // namespace boost
0095 
0096 #endif