0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-15 20:31:16 +08:00

Introduced field template to make result_row_t less specific.

It is sufficient to have name and type. There is no need for the result
"to know" what exact expression was used to define the column.

Surprisingly, template alias creates new templates (in contrast to
non-template using, which really just creates an alias of a type).

template<typename T> struct A{};

struct X
{
  template<typename T>
    using U = A<T>;
};

struct Y
{
  template<typename T>
    using U = A<T>;
  template<>
    using U<int> = X;
};

template<template<typename> class X>
struct Z{};

static_assert(std::is_same<X::U<int>, Y::U<int>>::value, "class aliases are really just aliases");
static_assert(not std::is_same<Z<X::U>, Z<Y::U>>::value, "template aliases are new templates");

int main()
{
}
This commit is contained in:
Roland Bock 2013-09-13 07:24:41 +02:00
parent 9c1e75cd89
commit 2defeff18e
3 changed files with 16 additions and 3 deletions

View File

@ -28,7 +28,7 @@
#define SQLPP_RESULT_ROW_H
#include <sqlpp11/raw_result_row.h>
#include <sqlpp11/multi_column.h>
#include <sqlpp11/field.h>
#include <iostream>
namespace sqlpp
{
@ -59,7 +59,7 @@ namespace sqlpp
};
template<size_t level, size_t index, typename AliasProvider, typename... Col, typename... Rest>
struct result_row_impl<level, index, multi_column_t<AliasProvider, std::tuple<Col...>>, Rest...>:
struct result_row_impl<level, index, multi_field_t<AliasProvider, std::tuple<Col...>>, Rest...>:
public AliasProvider::template _member_t<result_row_impl<level + 1, index, Col...>>, // level prevents identical closures to be present twice in the inheritance tree
public result_row_impl<level, index + sizeof...(Col), Rest...>
{

View File

@ -41,6 +41,7 @@
#include <sqlpp11/order_by.h>
#include <sqlpp11/limit.h>
#include <sqlpp11/expression.h>
#include <sqlpp11/field.h>
#include <sqlpp11/detail/wrong.h>
#include <sqlpp11/detail/make_flag_tuple.h>
@ -102,7 +103,7 @@ namespace sqlpp
using add_limit_t = select_t<Flags, ExpressionList, From, Where, GroupBy, Having, OrderBy, limit_t, Offset>;
using add_offset_t = select_t<Flags, ExpressionList, From, Where, GroupBy, Having, OrderBy, Limit, offset_t>;
using _result_row_t = result_row_t<NamedExpr...>;
using _result_row_t = result_row_t<make_field_t<NamedExpr>...>;
// Indicators
using _value_type = typename std::conditional<

View File

@ -38,6 +38,7 @@ DbMock db;
int main()
{
TabSample t;
TabFoo f;
// Test a table
{
@ -249,6 +250,17 @@ int main()
static_assert(not sqlpp::is_value_t<decltype(a)>::value, "a multi_column is not a value");
}
// Test that result sets with identical name/value combinations have identical types
{
auto a = select(t.alpha);
auto b = select(f.omega.as(t.alpha));
using A = typename decltype(a)::_result_row_t;
using B = typename decltype(b)::_result_row_t;
static_assert(std::is_same<decltype(t.alpha)::_value_type::_base_value_type, decltype(f.omega)::_value_type::_base_value_type>::value, "Two bigint columns must have identical base_value_type");
//A x = std::declval<B>();
static_assert(std::is_same<A, B>::value, "select with identical columns(name/value_type) need to have identical result_types");
}
static_assert(sqlpp::is_select_flag_t<decltype(sqlpp::all)>::value, "sqlpp::all has to be a select_flag");
using T = sqlpp::detail::wrap_operand<int>::type;