-
Notifications
You must be signed in to change notification settings - Fork 548
Closed
Labels
Description
In the helper function called by getColumns<typename T, int N>, the returned T is constructed by T():
// Helper function called by getColums<typename T, int N>
template<typename T, const int... Is>
T Statement::getColumns(const std::integer_sequence<int, Is...>)
{
return T(Column(mStmtPtr, Is)...);
}
If I pass a struct without a constructor like:
struct Test { int a; double b; const char* c; };
auto test = query.getColumns<Test, 3>();
There will be a error:
error C2440: '<function-style-cast>': cannot convert from 'initializer list' to 'Statement_getColumns_Test::TestBody::Test'
I believe the initializer list, that is, the expanded parameter pack, will be first cast to Test, and then the move constructor will be invoked.
If I change T() to T{} like:
// Helper function called by getColums<typename T, int N>
template<typename T, const int... Is>
T Statement::getColumns(const std::integer_sequence<int, Is...>)
{
return T{Column(mStmtPtr, Is)...};
}
The error will be gone. The initializer list will be directly passed to construct the struct Test.
So I think it would be easier to use without defining a constructor for each struct when using getColumns(), by changing T() to T{}.
Please correct me if I'm wrong. Thanks.