diff --git a/include/sqlpp11/column.h b/include/sqlpp11/column.h index 3acd42e3..bd2a8671 100644 --- a/include/sqlpp11/column.h +++ b/include/sqlpp11/column.h @@ -26,6 +26,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -39,7 +40,8 @@ namespace sqlpp { #warning: need to reactivate column operators? template - struct column_t// : public expression_operators, typename ColumnSpec::value_type>, + struct column_t : public enable_as> + // : public expression_operators, typename ColumnSpec::value_type>, // public column_operators, typename ColumnSpec::value_type> { struct _traits @@ -69,12 +71,6 @@ namespace sqlpp return _table{}; } - template - auto as(const AliasProvider& alias_provider) const -> as_expression - { - return as(*this, alias_provider); - } - sqlpp::compat::optional if_(bool condition) const { return condition ? sqlpp::compat::make_optional(*this) : sqlpp::compat::nullopt; diff --git a/include/sqlpp11/enable_as.h b/include/sqlpp11/enable_as.h new file mode 100644 index 00000000..c54f3152 --- /dev/null +++ b/include/sqlpp11/enable_as.h @@ -0,0 +1,51 @@ +#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: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. 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 + +namespace sqlpp +{ + // To be used as CRTP base for expressions that should offer the as() member function. + template + class enable_as + { + constexpr decltype(auto) derived() const + { + return static_cast(*this); + } + + public: + template + constexpr auto as(const AliasProvider& alias) const + { + return ::sqlpp::as(this->derived(), alias); + } + }; + +} // namespace sqlpp