diff --git a/include/sqlpp11/detail/get_last.h b/include/sqlpp11/detail/get_last.h new file mode 100644 index 00000000..02bacd4b --- /dev/null +++ b/include/sqlpp11/detail/get_last.h @@ -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 + +namespace sqlpp +{ + namespace detail + { + template class Predicate, typename Default, typename... T> + struct get_last_if_impl; + + template class Predicate, typename Default> + struct get_last_if_impl + { + using type = Default; + }; + + template class Predicate, typename Default, typename T, typename... Rest> + struct get_last_if_impl + { + using rest = typename get_last_if_impl::type; + using type = typename std::conditional::value and Predicate::value, + T, + rest>::type; + }; + + template class Predicate, typename Default, typename... T> + using get_last_if = typename get_last_if_impl::type; + } +} + + +#endif diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index 2f5dc271..976d4ef4 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -48,6 +48,7 @@ #include #include +#include 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; + // 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::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; diff --git a/include/sqlpp11/vendor/noop.h b/include/sqlpp11/vendor/noop.h index e0c28ef1..1a7bcfe5 100644 --- a/include/sqlpp11/vendor/noop.h +++ b/include/sqlpp11/vendor/noop.h @@ -35,7 +35,8 @@ namespace sqlpp { struct noop { - using is_noop = std::true_type; + using _traits = make_traits; + using _recursive_traits = make_recursive_traits<>; }; template