Skip to content

Commit

Permalink
Add automatic type conversion to row::get()
Browse files Browse the repository at this point in the history
Convert to the requested type if lossless conversion is possible to make
the behaviour more compatible with the previous SOCI versions and more
useful.

See #1127.
  • Loading branch information
zann1x authored and vadz committed Mar 27, 2024
1 parent 1b3bd79 commit ae07cd5
Show file tree
Hide file tree
Showing 6 changed files with 507 additions and 36 deletions.
8 changes: 5 additions & 3 deletions include/soci/row.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class SOCI_DECL row
template <typename T>
inline void add_holder(T* t, indicator* ind)
{
holders_.push_back(new details::type_holder<T>(t));
holders_.push_back(details::holder::make_holder(t));
indicators_.push_back(ind);
}

Expand All @@ -78,7 +78,8 @@ class SOCI_DECL row
typedef typename type_conversion<T>::base_type base_type;
static_assert(details::can_use_from_base<type_conversion<T>>(),
"Can't use row::get() with this type (not convertible/copy-assignable from base_type) - did you mean to use move_as?");
base_type const& baseVal = holders_.at(pos)->get<base_type>();
base_type const& baseVal =
holders_.at(pos)->get<base_type>(details::value_cast_tag{});

T ret;
type_conversion<T>::from_base(baseVal, *indicators_.at(pos), ret);
Expand All @@ -91,7 +92,8 @@ class SOCI_DECL row
typedef typename type_conversion<T>::base_type base_type;
static_assert(details::can_use_move_from_base<T, base_type>(),
"row::move_as() can only be called with types that can be instantiated from a base type rvalue reference");
base_type & baseVal = holders_.at(pos)->get<base_type>();
base_type & baseVal =
holders_.at(pos)->get<base_type>(details::value_reference_tag{});

T ret;
type_conversion<T>::move_from_base(baseVal, *indicators_.at(pos), ret);
Expand Down
Loading

0 comments on commit ae07cd5

Please sign in to comment.