diff --git a/include/sqlpp11/assignment_list.h b/include/sqlpp11/assignment_list.h index 756a2436..3cf598fd 100644 --- a/include/sqlpp11/assignment_list.h +++ b/include/sqlpp11/assignment_list.h @@ -27,29 +27,13 @@ #ifndef SQLPP_ASSIGNMENT_LIST_H #define SQLPP_ASSIGNMENT_LIST_H -#include #include #include #include -#include +#include namespace sqlpp { - namespace detail - { - template - struct dynamic_assignment_list - { - using type = std::vector>; - }; - - template<> - struct dynamic_assignment_list - { - using type = std::vector; - }; - }; - template class ProhibitPredicate, typename... Assignments> struct assignment_list_t { @@ -75,7 +59,7 @@ namespace sqlpp { static_assert(is_assignment_t::type>::value, "set() arguments require to be assigments"); static_assert(not ProhibitPredicate::type::column_type>::value, "set() argument must not be updated"); - _dynamic_assignments.push_back(std::forward(assignment)); + _dynamic_assignments.emplace_back(std::forward(assignment)); } template @@ -83,18 +67,11 @@ namespace sqlpp { os << " SET "; detail::serialize_tuple(os, db, _assignments, ','); - bool first = sizeof...(Assignments) == 0; - for (const auto& assignment : _dynamic_assignments) - { - if (not first) - os << ','; - assignment.serialize(os, db); - first = false; - } + _dynamic_assignments.serialize(os, db, sizeof...(Assignments) == 0); } - std::tuple _assignments; - typename detail::dynamic_assignment_list::type _dynamic_assignments; + std::tuple::type...> _assignments; + typename detail::serializable_list _dynamic_assignments; }; } diff --git a/include/sqlpp11/insert_list.h b/include/sqlpp11/insert_list.h index 78feb6e0..e7e02270 100644 --- a/include/sqlpp11/insert_list.h +++ b/include/sqlpp11/insert_list.h @@ -27,11 +27,10 @@ #ifndef SQLPP_INSERT_LIST_H #define SQLPP_INSERT_LIST_H -#include #include #include #include -#include +#include namespace sqlpp { @@ -47,18 +46,6 @@ namespace sqlpp os << " DEFAULT VALUES"; } - template - struct dynamic_column_list - { - using type = std::vector>; - }; - - template<> - struct dynamic_column_list - { - using type = std::vector; - }; - template struct insert_column { @@ -107,8 +94,8 @@ namespace sqlpp { static_assert(is_assignment_t::type>::value, "set() arguments require to be assigments"); static_assert(not ProhibitPredicate::type>::value, "set() argument must not be used in insert"); - _dynamic_columns.push_back(std::forward(assignment._lhs)); - _dynamic_values.push_back(std::forward(assignment._rhs)); + _dynamic_columns.emplace_back(detail::insert_column{std::forward(assignment._lhs)}); + _dynamic_values.emplace_back(std::forward(assignment._rhs)); } template @@ -120,38 +107,22 @@ namespace sqlpp } else { + constexpr bool first = sizeof...(Assignments) == 0; + os << " ("; detail::serialize_tuple(os, db, _columns, ','); - { - bool first = sizeof...(Assignments) == 0; - for (const auto column : _dynamic_columns) - { - if (not first) - os << ','; - column.serialize(os, db); - first = false; - } - } + _dynamic_columns.serialize(os, db, first); os << ") VALUES ("; detail::serialize_tuple(os, db, _values, ','); - { - bool first = sizeof...(Assignments) == 0; - for (const auto column : _dynamic_values) - { - if (not first) - os << ','; - column.serialize(os, db); - first = false; - } - } + _dynamic_values.serialize(os, db, first); os << ")"; } } std::tuple...> _columns; std::tuple _values; - typename detail::dynamic_column_list::type _dynamic_columns; - typename detail::dynamic_column_list::type _dynamic_values; + typename detail::serializable_list _dynamic_columns; + typename detail::serializable_list _dynamic_values; }; }