0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-16 04:47:18 +08:00

Move index_sequence into compat/utility.h

This commit is contained in:
Roland Bock 2024-08-10 09:53:33 +02:00
parent 1339cbd0e6
commit 892583582b
7 changed files with 60 additions and 46 deletions

View File

@ -106,7 +106,7 @@ namespace sqlpp
private:
template <size_t... Indexes>
auto columns_from_tuple(detail::index_sequence<Indexes...>, std::tuple<Assignments...> assignments)
auto columns_from_tuple(::sqlpp::index_sequence<Indexes...>, std::tuple<Assignments...> assignments)
-> decltype(_columns)
{
(void)assignments;
@ -115,12 +115,12 @@ namespace sqlpp
auto columns_from_tuple(std::tuple<Assignments...> assignments) -> decltype(_columns)
{
const auto seq = detail::make_index_sequence<sizeof...(Assignments)>{};
const auto seq = ::sqlpp::make_index_sequence<sizeof...(Assignments)>{};
return columns_from_tuple(seq, assignments);
}
template <size_t... Indexes>
auto values_from_tuple(detail::index_sequence<Indexes...>, std::tuple<Assignments...> assignments)
auto values_from_tuple(::sqlpp::index_sequence<Indexes...>, std::tuple<Assignments...> assignments)
-> decltype(_values)
{
(void)assignments;
@ -129,7 +129,7 @@ namespace sqlpp
auto values_from_tuple(std::tuple<Assignments...> assignments) -> decltype(_values)
{
const auto seq = detail::make_index_sequence<sizeof...(Assignments)>{};
const auto seq = ::sqlpp::make_index_sequence<sizeof...(Assignments)>{};
return values_from_tuple(seq, assignments);
}
};

View File

@ -62,8 +62,7 @@ namespace sqlpp
{
}
#warning: Can we make char_traits<char>::length constexpr
constexpr string_view(const char* data) : _data(data), _size(std::char_traits<char>::length(data))
string_view(const char* data) : _data(data), _size(std::char_traits<char>::length(data))
{
}

View File

@ -1,7 +1,7 @@
#pragma once
/*
* Copyright (c) 2013-2015, Roland Bock
* Copyright (c) 2013, Roland Bock
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -26,16 +26,31 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <type_traits>
#include <utility>
#ifdef _MSVC_LANG
#define CXX_STD_VER _MSVC_LANG
#else
#define CXX_STD_VER __cplusplus
#endif
#if CXX_STD_VER >= 201402L
#include <string_view>
namespace sqlpp
{
template <std::size_t... Ints>
using index_sequence = std::index_sequence<Ints...>;
template <std::size_t N>
using make_index_sequence = std::make_index_sequence<N>;
} // namespace sqlpp
#else // incomplete backport of utility.h
namespace sqlpp
{
namespace detail
{
// Note: This is a minimalistic implementation of index_sequence available in C++14
// It should be replaced once the project is moved to C++14 or beyond
template <std::size_t... Ints>
struct index_sequence
class index_sequence
{
};
@ -56,5 +71,6 @@ namespace sqlpp
template <std::size_t N>
using make_index_sequence = typename make_index_sequence_impl<index_sequence<>, N>::type;
} // namespace detail
} // namespace sqlpp
#endif

View File

@ -30,7 +30,7 @@
#include <sqlpp11/core/type_traits.h>
#include <sqlpp11/core/wrong.h>
#include <sqlpp11/core/detail/index_sequence.h>
#include <sqlpp11/core/compat/utility.h>
#include <sqlpp11/core/detail/type_vector.h>
namespace sqlpp
@ -52,12 +52,12 @@ namespace sqlpp
template <typename Target>
void _bind(Target& target) const
{
_bind_impl(target, detail::make_index_sequence<size::value>{});
_bind_impl(target, ::sqlpp::make_index_sequence<size::value>{});
}
private:
template <typename Target, size_t... Is>
void _bind_impl(Target& target, const detail::index_sequence<Is...>& /*unused*/) const
void _bind_impl(Target& target, const ::sqlpp::index_sequence<Is...>& /*unused*/) const
{
using swallow = int[]; // see core/interpret_tuple.h
(void)swallow{0, (std::tuple_element<Is, _member_tuple_t>::type::operator()()._bind(target, Is), 0)...};

View File

@ -29,7 +29,7 @@
#include <tuple>
#include <sqlpp11/core/type_traits.h>
#include <sqlpp11/core/serialize.h>
#include <sqlpp11/core/detail/index_sequence.h>
#include <sqlpp11/core/compat/utility.h>
namespace sqlpp
{
@ -56,7 +56,7 @@ namespace sqlpp
const Separator& separator,
Context& context,
const UseBraces& useBraces,
const detail::index_sequence<Is...> &
const ::sqlpp::index_sequence<Is...> &
/*unused*/) -> Context&
{
// Note: A braced-init-list does guarantee the order of evaluation according to 12.6.1 [class.explicit.init]
@ -75,13 +75,13 @@ namespace sqlpp
auto interpret_tuple(const Tuple& t, const Separator& separator, Context& context) -> Context&
{
return interpret_tuple_impl(t, separator, context, std::true_type{},
detail::make_index_sequence<std::tuple_size<Tuple>::value>{});
::sqlpp::make_index_sequence<std::tuple_size<Tuple>::value>{});
}
template <typename Tuple, typename Separator, typename Context>
auto interpret_tuple_without_braces(const Tuple& t, const Separator& separator, Context& context) -> Context&
{
return interpret_tuple_impl(t, separator, context, std::false_type{},
detail::make_index_sequence<std::tuple_size<Tuple>::value>{});
::sqlpp::make_index_sequence<std::tuple_size<Tuple>::value>{});
}
} // namespace sqlpp

View File

@ -1,7 +1,7 @@
#pragma once
/*
* Copyright (c) 2013-2015, Roland Bock
* Copyright (c) 2013, Roland Bock
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -27,8 +27,7 @@
*/
#include <type_traits>
#warning: move index_sequence into compat
#include <sqlpp11/core/detail/index_sequence.h>
#include <sqlpp11/core/compat/utility.h>
namespace sqlpp
{
@ -41,13 +40,13 @@ namespace sqlpp
struct make_char_sequence_impl;
template <std::size_t N, const char* s, std::size_t... i>
struct make_char_sequence_impl<N, s, sqlpp::detail::index_sequence<i...>>
struct make_char_sequence_impl<N, s, ::sqlpp::index_sequence<i...>>
{
using type = char_sequence<s[i]...>;
};
template <std::size_t N, const char* Input>
using make_char_sequence =
typename make_char_sequence_impl<N, Input, sqlpp::detail::make_index_sequence<N - 1>>::type;
typename make_char_sequence_impl<N, Input, ::sqlpp::make_index_sequence<N - 1>>::type;
} // namespace sqlpp

View File

@ -28,7 +28,7 @@
#include <utility>
#include <sqlpp11/core/compat/string_view.h>
#include <sqlpp11/core/detail/index_sequence.h>
#include <sqlpp11/core/compat/utility.h>
#include <sqlpp11/core/field_spec.h>
#include <sqlpp11/core/query/result_row_fwd.h>
@ -72,7 +72,7 @@ namespace sqlpp
};
template <typename Db, std::size_t... Is, typename... FieldSpecs>
struct result_row_impl<Db, detail::index_sequence<Is...>, FieldSpecs...>
struct result_row_impl<Db, ::sqlpp::index_sequence<Is...>, FieldSpecs...>
: public result_field<Db, Is, FieldSpecs>...
{
result_row_impl() = default;
@ -109,9 +109,9 @@ namespace sqlpp
template <typename Db, typename... FieldSpecs>
struct result_row_t
: public detail::result_row_impl<Db, detail::make_index_sequence<sizeof...(FieldSpecs)>, FieldSpecs...>
: public detail::result_row_impl<Db, ::sqlpp::make_index_sequence<sizeof...(FieldSpecs)>, FieldSpecs...>
{
using _impl = detail::result_row_impl<Db, detail::make_index_sequence<sizeof...(FieldSpecs)>, FieldSpecs...>;
using _impl = detail::result_row_impl<Db, ::sqlpp::make_index_sequence<sizeof...(FieldSpecs)>, FieldSpecs...>;
bool _is_valid{false};
result_row_t() : _impl()