mirror of
https://github.com/rbock/sqlpp11.git
synced 2026-01-05 04:30:43 -06:00
Determining column_list in a more generic way.
By finding the last parameter which is a return value.
This commit is contained in:
60
include/sqlpp11/detail/get_last.h
Normal file
60
include/sqlpp11/detail/get_last.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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_DETAIL_GET_LAST_H
|
||||
#define SQLPP_DETAIL_GET_LAST_H
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template<template<typename> class Predicate, typename Default, typename... T>
|
||||
struct get_last_if_impl;
|
||||
|
||||
template<template<typename> class Predicate, typename Default>
|
||||
struct get_last_if_impl<Predicate, Default>
|
||||
{
|
||||
using type = Default;
|
||||
};
|
||||
|
||||
template<template<typename> class Predicate, typename Default, typename T, typename... Rest>
|
||||
struct get_last_if_impl<Predicate, Default, T, Rest...>
|
||||
{
|
||||
using rest = typename get_last_if_impl<Predicate, Default, Rest...>::type;
|
||||
using type = typename std::conditional<std::is_same<rest, Default>::value and Predicate<T>::value,
|
||||
T,
|
||||
rest>::type;
|
||||
};
|
||||
|
||||
template<template<typename> class Predicate, typename Default, typename... T>
|
||||
using get_last_if = typename get_last_if_impl<Predicate, Default, T...>::type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -48,6 +48,7 @@
|
||||
#include <sqlpp11/vendor/policy_update.h>
|
||||
|
||||
#include <sqlpp11/detail/arg_selector.h>
|
||||
#include <sqlpp11/detail/get_last.h>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
@@ -135,18 +136,20 @@ namespace sqlpp
|
||||
provided_tables_of<_from_t> // Hint: extra_tables_t is not used here because it is just a helper for dynamic .add_*() methods and should not change the structural integrity
|
||||
>;
|
||||
|
||||
using _result_provider = detail::get_last_if<is_return_value_t, vendor::noop, FlagList, ColumnList, From, ExtraTables, Where, GroupBy, Having, OrderBy, Limit, Offset>;
|
||||
|
||||
// A select can be used as a pseudo table if
|
||||
// - at least one column is selected
|
||||
// - the select is complete (leaks no tables)
|
||||
using _can_be_used_as_table = typename std::conditional<
|
||||
is_select_column_list_t<_column_list_t>::value and _required_tables::size::value == 0,
|
||||
is_select_column_list_t<_result_provider>::value and _required_tables::size::value == 0,
|
||||
std::true_type,
|
||||
std::false_type
|
||||
>::type;
|
||||
|
||||
using _value_type = typename std::conditional<
|
||||
detail::make_type_set_if_t<is_missing_t, FlagList, ColumnList, From, ExtraTables, Where, GroupBy, Having, OrderBy, Limit, Offset>::size::value == 0,
|
||||
value_type_of<_column_list_t>,
|
||||
value_type_of<_result_provider>,
|
||||
no_value_t // if a required statement part is missing (columns in a select), then the statement cannot be used as a value
|
||||
>::type;
|
||||
|
||||
|
||||
3
include/sqlpp11/vendor/noop.h
vendored
3
include/sqlpp11/vendor/noop.h
vendored
@@ -35,7 +35,8 @@ namespace sqlpp
|
||||
{
|
||||
struct noop
|
||||
{
|
||||
using is_noop = std::true_type;
|
||||
using _traits = make_traits<no_value_t, ::sqlpp::tag::noop>;
|
||||
using _recursive_traits = make_recursive_traits<>;
|
||||
};
|
||||
|
||||
template<typename Context>
|
||||
|
||||
Reference in New Issue
Block a user