Skip to content

Commit e12d6c3

Browse files
committed
Add trait for compatible values of any type
1 parent 6367ec5 commit e12d6c3

File tree

2 files changed

+10
-37
lines changed

2 files changed

+10
-37
lines changed

hdr/sqlite_modern_cpp.h

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -127,50 +127,14 @@ namespace sqlite {
127127

128128
friend class row_iterator;
129129
};
130-
namespace detail {
131-
template <typename Type>
132-
struct is_sqlite_value : public std::integral_constant<
133-
bool,
134-
std::is_floating_point<Type>::value
135-
|| std::is_integral<Type>::value
136-
|| std::is_same<std::string, Type>::value
137-
|| std::is_same<std::u16string, Type>::value
138-
|| std::is_same<sqlite_int64, Type>::value
139-
> { };
140-
template <typename Type, typename Allocator>
141-
struct is_sqlite_value< std::vector<Type, Allocator> > : public std::integral_constant<
142-
bool,
143-
std::is_floating_point<Type>::value
144-
|| std::is_integral<Type>::value
145-
|| std::is_same<sqlite_int64, Type>::value
146-
> { };
147-
template <typename T>
148-
struct is_sqlite_value< std::unique_ptr<T> > : public is_sqlite_value<T> {};
149-
#ifdef MODERN_SQLITE_STD_VARIANT_SUPPORT
150-
template <typename ...Args>
151-
struct is_sqlite_value< std::variant<Args...> > : public std::integral_constant<
152-
bool,
153-
true
154-
> { };
155-
#endif
156-
#ifdef MODERN_SQLITE_STD_OPTIONAL_SUPPORT
157-
template <typename T>
158-
struct is_sqlite_value< optional<T> > : public is_sqlite_value<T> {};
159-
#endif
160-
161-
#ifdef _MODERN_SQLITE_BOOST_OPTIONAL_SUPPORT
162-
template <typename T>
163-
struct is_sqlite_value< boost::optional<T> > : public is_sqlite_value<T> {};
164-
#endif
165-
}
166130

167131
class row_iterator {
168132
public:
169133
class value_type {
170134
public:
171135
value_type(database_binder *_binder): _binder(_binder) {};
172136
template<class T>
173-
typename std::enable_if<detail::is_sqlite_value<T>::value, value_type &>::type operator >>(T &result) {
137+
typename std::enable_if<is_sqlite_value<T>::value, value_type &>::type operator >>(T &result) {
174138
get_col_from_db(_binder->_stmt.get(), next_index++, result);
175139
return *this;
176140
}

hdr/sqlite_modern_cpp/type_wrapper.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@
3838
namespace sqlite {
3939
template<class T, int Type, class = void>
4040
struct has_sqlite_type : std::false_type {};
41+
42+
template<class T>
43+
using is_sqlite_value = std::integral_constant<bool, false
44+
|| has_sqlite_type<T, SQLITE_NULL>::value
45+
|| has_sqlite_type<T, SQLITE_INTEGER>::value
46+
|| has_sqlite_type<T, SQLITE_FLOAT>::value
47+
|| has_sqlite_type<T, SQLITE_TEXT>::value
48+
|| has_sqlite_type<T, SQLITE_BLOB>::value
49+
>;
4150

4251
template<class T, int Type>
4352
struct has_sqlite_type<T&, Type> : has_sqlite_type<T, Type> {};

0 commit comments

Comments
 (0)