mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 04:47:18 +08:00
71 lines
3.1 KiB
C++
71 lines
3.1 KiB
C++
/*
|
|
* Copyright (c) 2013-2014, Roland Bock
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
* are permitted provided that the following conditions are met:
|
|
*
|
|
* Redistributions of source code must retain the above copyright notice, this
|
|
* list of conditions and the following disclaimer.
|
|
*
|
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
|
* list of conditions and the following disclaimer in the documentation and/or
|
|
* other materials provided with the distribution.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#ifndef SQLPP_INTERPRET_TUPLE_H
|
|
#define SQLPP_INTERPRET_TUPLE_H
|
|
|
|
#include <tuple>
|
|
#include <sqlpp11/type_traits.h>
|
|
#include <sqlpp11/serialize.h>
|
|
#include <sqlpp11/detail/index_sequence.h>
|
|
|
|
namespace sqlpp
|
|
{
|
|
template<typename Element, typename Separator, typename Context>
|
|
static void interpret_tuple_element(const Element& element, const Separator& separator, Context& context, size_t index)
|
|
{
|
|
if (index)
|
|
context << separator;
|
|
if (requires_braces_t<Element>::value)
|
|
context << "(";
|
|
serialize(element, context);
|
|
if (requires_braces_t<Element>::value)
|
|
context << ")";
|
|
}
|
|
|
|
template<typename Tuple, typename Separator, typename Context, size_t... Is>
|
|
auto interpret_tuple_impl(const Tuple& t, const Separator& separator, Context& context, const ::sqlpp::detail::index_sequence<Is...>&)
|
|
-> Context&
|
|
{
|
|
// Note: A braced-init-list does guarantee the order of evaluation according to 12.6.1 [class.explicit.init] paragraph 2 and 8.5.4 [dcl.init.list] paragraph 4.
|
|
// See for example: "http://en.cppreference.com/w/cpp/utility/integer_sequence"
|
|
// See also: "http://stackoverflow.com/questions/6245735/pretty-print-stdtuple/6245777#6245777"
|
|
// Beware of gcc-bug: "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51253", otherwise an empty swallow struct could be used
|
|
using swallow = int[];
|
|
(void) swallow{(interpret_tuple_element(std::get<Is>(t), separator, context, Is), 0)...};
|
|
return context;
|
|
}
|
|
|
|
template<typename Tuple, typename Separator, typename Context>
|
|
auto interpret_tuple(const Tuple& t, const Separator& separator, Context& context)
|
|
-> Context&
|
|
{
|
|
return interpret_tuple_impl(t, separator, context, ::sqlpp::detail::make_index_sequence<std::tuple_size<Tuple>::value>{});
|
|
}
|
|
}
|
|
|
|
#endif
|