diff --git a/include/sqlpp11/core/aggregate_function/avg.h b/include/sqlpp11/core/aggregate_function/avg.h index 69f9a805..1b6336d8 100644 --- a/include/sqlpp11/core/aggregate_function/avg.h +++ b/include/sqlpp11/core/aggregate_function/avg.h @@ -48,7 +48,6 @@ namespace sqlpp using _traits = make_traits; using _can_be_null = std::false_type; - using _is_aggregate_expression = std::true_type; constexpr avg_t(Expr expr) : _expr(std::move(expr)) { @@ -64,7 +63,7 @@ namespace sqlpp }; template - struct is_aggregate> : public std::true_type + struct contains_aggregate> : public std::true_type { }; diff --git a/include/sqlpp11/core/aggregate_function/count.h b/include/sqlpp11/core/aggregate_function/count.h index 03550926..bffbf802 100644 --- a/include/sqlpp11/core/aggregate_function/count.h +++ b/include/sqlpp11/core/aggregate_function/count.h @@ -48,7 +48,6 @@ namespace sqlpp using _traits = make_traits; using _can_be_null = std::false_type; - using _is_aggregate_expression = std::true_type; constexpr count_t(Expr expr) : _expr(std::move(expr)) { @@ -64,7 +63,7 @@ namespace sqlpp }; template - struct is_aggregate> : public std::true_type + struct contains_aggregate> : public std::true_type { }; diff --git a/include/sqlpp11/core/aggregate_function/max.h b/include/sqlpp11/core/aggregate_function/max.h index 008792ae..2cd5ad8a 100644 --- a/include/sqlpp11/core/aggregate_function/max.h +++ b/include/sqlpp11/core/aggregate_function/max.h @@ -47,7 +47,6 @@ namespace sqlpp { using _traits = make_traits, tag::is_expression, tag::is_selectable>; using _can_be_null = std::true_type; - using _is_aggregate_expression = std::true_type; constexpr max_t(Expr expr) : _expr(std::move(expr)) { @@ -63,7 +62,7 @@ namespace sqlpp }; template - struct is_aggregate> : public std::true_type + struct contains_aggregate> : public std::true_type { }; diff --git a/include/sqlpp11/core/aggregate_function/min.h b/include/sqlpp11/core/aggregate_function/min.h index 78b78ee1..42b36032 100644 --- a/include/sqlpp11/core/aggregate_function/min.h +++ b/include/sqlpp11/core/aggregate_function/min.h @@ -47,7 +47,6 @@ namespace sqlpp { using _traits = make_traits, tag::is_expression, tag::is_selectable>; using _can_be_null = std::true_type; - using _is_aggregate_expression = std::true_type; constexpr min_t(Expr expr) : _expr(std::move(expr)) { @@ -63,7 +62,7 @@ namespace sqlpp }; template - struct is_aggregate> : public std::true_type + struct contains_aggregate> : public std::true_type { }; diff --git a/include/sqlpp11/core/aggregate_function/over.h b/include/sqlpp11/core/aggregate_function/over.h index 776f621a..0441cfd6 100644 --- a/include/sqlpp11/core/aggregate_function/over.h +++ b/include/sqlpp11/core/aggregate_function/over.h @@ -50,11 +50,6 @@ namespace sqlpp Expr _expr; }; - template - struct is_aggregate> : public is_aggregate - { - }; - template struct name_tag_of> : public name_tag_of {}; @@ -67,7 +62,7 @@ namespace sqlpp struct value_type_of>: public value_type_of {}; template - using check_over_args = ::sqlpp::enable_if_t::value>; + using check_over_args = ::sqlpp::enable_if_t::value>; template auto to_sql_string(Context& context, const over_t& t) -> std::string diff --git a/include/sqlpp11/core/aggregate_function/sum.h b/include/sqlpp11/core/aggregate_function/sum.h index 5d4eac34..b3fe1122 100644 --- a/include/sqlpp11/core/aggregate_function/sum.h +++ b/include/sqlpp11/core/aggregate_function/sum.h @@ -47,7 +47,6 @@ namespace sqlpp { using _traits = make_traits, tag::is_expression, tag::is_selectable>; using _can_be_null = std::true_type; - using _is_aggregate_expression = std::true_type; constexpr sum_t(Expr expr) : _expr(std::move(expr)) { @@ -63,7 +62,7 @@ namespace sqlpp }; template - struct is_aggregate> : public std::true_type + struct contains_aggregate> : public std::true_type { }; diff --git a/include/sqlpp11/core/type_traits.h b/include/sqlpp11/core/type_traits.h index e0e0db41..1f8eae67 100644 --- a/include/sqlpp11/core/type_traits.h +++ b/include/sqlpp11/core/type_traits.h @@ -43,6 +43,8 @@ #include #include #include +#include +#include namespace sqlpp { @@ -126,7 +128,6 @@ namespace sqlpp template using value_type_of_t = typename value_type_of::type; -#warning: Add partial specialization to handle const? template struct value_type_of<::sqlpp::optional> { @@ -505,13 +506,6 @@ namespace sqlpp using is_database = typename std::conditional::value, std::false_type, std::true_type>::type; - template - struct nodes_of { - using type = detail::type_vector<>; - }; - template - using nodes_of_t = typename nodes_of::type; - #define SQLPP_RECURSIVE_TRAIT_SET_GENERATOR(trait) \ namespace detail \ { \ @@ -585,13 +579,6 @@ namespace sqlpp ; }; - template - struct is_aggregate : public std::false_type{}; - -#warning: Need to make this recursive! and then add tests! - template - struct contains_aggregate : public std::false_type{}; - namespace detail { template diff --git a/include/sqlpp11/core/type_traits/aggregates.h b/include/sqlpp11/core/type_traits/aggregates.h new file mode 100644 index 00000000..0fae846e --- /dev/null +++ b/include/sqlpp11/core/type_traits/aggregates.h @@ -0,0 +1,47 @@ +#pragma once + +/* + * Copyright (c) 2024, 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. + */ + +#include +#include +#include + +namespace sqlpp +{ + template + struct contains_aggregate : public std::integral_constant>::value> + { + }; + + template + struct contains_aggregate> + : public std::integral_constant::value...>::value> + { + }; + +} // namespace sqlpp11 + diff --git a/include/sqlpp11/core/type_traits/nodes_of.h b/include/sqlpp11/core/type_traits/nodes_of.h new file mode 100644 index 00000000..321a8494 --- /dev/null +++ b/include/sqlpp11/core/type_traits/nodes_of.h @@ -0,0 +1,43 @@ +#pragma once + +/* + * Copyright (c) 2024, 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. + */ + +#include + +namespace sqlpp +{ + + template + struct nodes_of + { + using type = detail::type_vector<>; + }; + template + using nodes_of_t = typename nodes_of::type; + +} // namespace sqlpp11 + diff --git a/tests/core/types/CMakeLists.txt b/tests/core/types/CMakeLists.txt index 58a24dbd..37771630 100644 --- a/tests/core/types/CMakeLists.txt +++ b/tests/core/types/CMakeLists.txt @@ -37,3 +37,4 @@ test_compile(value) add_subdirectory(aggregate_function) add_subdirectory(operator) +add_subdirectory(type_traits) diff --git a/tests/core/types/type_traits/CMakeLists.txt b/tests/core/types/type_traits/CMakeLists.txt new file mode 100644 index 00000000..2786010e --- /dev/null +++ b/tests/core/types/type_traits/CMakeLists.txt @@ -0,0 +1,32 @@ +# Copyright (c) 2024, 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. + +function(test_compile name) + set(target sqlpp11_core_types_operator_${name}) + add_executable(${target} ${name}.cpp) + target_link_libraries(${target} PRIVATE sqlpp11::sqlpp11 sqlpp11_testing) +endfunction() + +test_compile(aggregates) + diff --git a/tests/core/types/type_traits/aggregates.cpp b/tests/core/types/type_traits/aggregates.cpp new file mode 100644 index 00000000..376cad8c --- /dev/null +++ b/tests/core/types/type_traits/aggregates.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2024, 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. + */ + +#include "MockDb.h" +#include "Sample.h" +#include + +namespace +{ + auto db = MockDb{}; + + template + using is_same_type = std::is_same, V>; +} + +template +void test_aggregates(Value v) +{ + auto v_not_null = sqlpp::value(v); + auto v_maybe_null = sqlpp::value(::sqlpp::make_optional(v)); + + using OptFloat = sqlpp::value_type_of_t<::sqlpp::optional>; + +#warning: Need to test contains_aggregate + +} + +int main() +{ + // boolean + test_avg(bool{true}); + + // integral + test_avg(int8_t{7}); + test_avg(int16_t{7}); + test_avg(int32_t{7}); + test_avg(int64_t{7}); + + // unsigned integral + test_avg(uint8_t{7}); + test_avg(uint16_t{7}); + test_avg(uint32_t{7}); + test_avg(uint64_t{7}); + + // floating point + test_avg(float{7.7}); + test_avg(double{7.7}); + +#warning: Should there be avg date time duration? +#if 0 + // date + test_avg(::sqlpp::chrono::day_point{}); + + // timestamp + test_avg(::sqlpp::chrono::microsecond_point{}); + using minute_point = std::chrono::time_point; + test_avg(minute_point{}); + + // time_of_day + test_avg(std::chrono::microseconds{}); +#endif +} +