Skip to content

Commit 64f911b

Browse files
committed
Return values instead of assigning to references
1 parent 8e9d851 commit 64f911b

File tree

2 files changed

+116
-159
lines changed

2 files changed

+116
-159
lines changed

hdr/sqlite_modern_cpp.h

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ namespace sqlite {
135135
value_type(database_binder *_binder): _binder(_binder) {};
136136
template<class T>
137137
typename std::enable_if<is_sqlite_value<T>::value, value_type &>::type operator >>(T &result) {
138-
get_col_from_db(_binder->_stmt.get(), next_index++, result);
138+
result = get_col_from_db(_binder->_stmt.get(), next_index++, result_type<T>());
139139
return *this;
140140
}
141141
template<class ...Types>
@@ -558,16 +558,20 @@ namespace sqlite {
558558
sqlite3_value** vals,
559559
Values&&... values
560560
) {
561-
typename std::remove_cv<
561+
using arg_type = typename std::remove_cv<
562562
typename std::remove_reference<
563563
typename utility::function_traits<
564564
typename Functions::first_type
565565
>::template argument<sizeof...(Values)>
566566
>::type
567-
>::type value{};
568-
get_val_from_db(vals[sizeof...(Values) - 1], value);
567+
>::type;
569568

570-
step<Count, Functions>(db, count, vals, std::forward<Values>(values)..., std::move(value));
569+
step<Count, Functions>(
570+
db,
571+
count,
572+
vals,
573+
std::forward<Values>(values)...,
574+
get_val_from_db(vals[sizeof...(Values) - 1], result_type<arg_type>()));
571575
}
572576

573577
template<
@@ -618,14 +622,18 @@ namespace sqlite {
618622
sqlite3_value** vals,
619623
Values&&... values
620624
) {
621-
typename std::remove_cv<
625+
using arg_type = typename std::remove_cv<
622626
typename std::remove_reference<
623627
typename utility::function_traits<Function>::template argument<sizeof...(Values)>
624628
>::type
625-
>::type value{};
626-
get_val_from_db(vals[sizeof...(Values)], value);
627-
628-
scalar<Count, Function>(db, count, vals, std::forward<Values>(values)..., std::move(value));
629+
>::type;
630+
631+
scalar<Count, Function>(
632+
db,
633+
count,
634+
vals,
635+
std::forward<Values>(values)...,
636+
get_val_from_db(vals[sizeof...(Values)], result_type<arg_type>()));
629637
}
630638

631639
template<

0 commit comments

Comments
 (0)