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

support for std::string_view when using C++17

This commit is contained in:
Daniel Evers 2019-01-24 15:08:43 +01:00 committed by Roland Bock
parent cf02a444d7
commit ac3a8290ff
2 changed files with 23 additions and 1 deletions

View File

@ -29,6 +29,9 @@
#include <string> #include <string>
#include <utility> #include <utility>
#if __cplusplus >= 201703L
#include <string_view>
#endif
#include <sqlpp11/type_traits.h> #include <sqlpp11/type_traits.h>
#include <sqlpp11/alias_operators.h> #include <sqlpp11/alias_operators.h>
#include <sqlpp11/serializer.h> #include <sqlpp11/serializer.h>
@ -50,6 +53,16 @@ namespace sqlpp
text_operand(_value_t t) : _t(std::move(t)) text_operand(_value_t t) : _t(std::move(t))
{ {
} }
#if __cplusplus >= 201703L
// allow construction from an std::string_view
text_operand(std::string_view t) : _t(t)
{
}
// additional const char* overload, required to disambiguate
text_operand(const char* t) : _t(t)
{
}
#endif
text_operand(const text_operand&) = default; text_operand(const text_operand&) = default;
text_operand(text_operand&&) = default; text_operand(text_operand&&) = default;

View File

@ -28,6 +28,9 @@
#define SQLPP11_DATA_TYPES_TEXT_WRAP_OPERAND_H #define SQLPP11_DATA_TYPES_TEXT_WRAP_OPERAND_H
#include <utility> #include <utility>
#if __cplusplus >= 201703L
#include <string_view>
#endif
#include <sqlpp11/type_traits.h> #include <sqlpp11/type_traits.h>
#include <sqlpp11/wrap_operand.h> #include <sqlpp11/wrap_operand.h>
@ -35,10 +38,16 @@ namespace sqlpp
{ {
struct text_operand; struct text_operand;
#if __cplusplus >= 201703L
using checked_type = std::string_view;
#else
using checked_type = std::string;
#endif
template <typename T> template <typename T>
struct wrap_operand< struct wrap_operand<
T, T,
typename std::enable_if<std::is_convertible<T, std::string>::value and not is_result_field_t<T>::value>::type> typename std::enable_if<std::is_convertible<T, checked_type>::value and not is_result_field_t<T>::value>::type>
{ {
using type = text_operand; using type = text_operand;
}; };