diff --git a/includes/cpp_redis/core/reply.hpp b/includes/cpp_redis/core/reply.hpp index 3233f0de..1cc959cc 100644 --- a/includes/cpp_redis/core/reply.hpp +++ b/includes/cpp_redis/core/reply.hpp @@ -195,7 +195,7 @@ namespace cpp_redis { explicit operator bool() const; public: - optional try_get_int() const; + optional_t try_get_int() const; public: /** diff --git a/includes/cpp_redis/misc/convert.hpp b/includes/cpp_redis/misc/convert.hpp index fa6f491e..4813ad74 100644 --- a/includes/cpp_redis/misc/convert.hpp +++ b/includes/cpp_redis/misc/convert.hpp @@ -30,12 +30,12 @@ namespace cpp_redis { class try_convert { public: template - static enableIf::value, optional > to_int(T value) { + static enableIf::value, optional_t > to_int(T value) { try { std::stringstream stream(value); int64_t x; stream >> x; - return optional()(x); + return optional_t(x); } catch (std::exception &exc) { return {}; } diff --git a/includes/cpp_redis/misc/optional.hpp b/includes/cpp_redis/misc/optional.hpp index a2227baf..f0dc6817 100644 --- a/includes/cpp_redis/misc/optional.hpp +++ b/includes/cpp_redis/misc/optional.hpp @@ -28,8 +28,12 @@ #if __cplusplus >= 201703L #include +namespace cpp_redis { template using optional_t = std::optional; + +template +using enableIf = typename std::enable_if::type; #else #include @@ -40,11 +44,12 @@ using enableIf = typename std::enable_if::type; template struct optional { - optional& - operator()(T value) { - m_value = value; - return *this; - } + optional(T value) : m_value(value) {} +// optional& +// operator()(T value) { +// m_value = value; +// return *this; +// } T m_value; diff --git a/sources/core/reply.cpp b/sources/core/reply.cpp index d024dbc6..c39da9ac 100644 --- a/sources/core/reply.cpp +++ b/sources/core/reply.cpp @@ -22,6 +22,7 @@ #include #include +#include namespace cpp_redis { @@ -45,12 +46,12 @@ namespace cpp_redis { m_int_val = other.m_int_val; } - optional reply::try_get_int() const { + optional_t reply::try_get_int() const { if (is_integer()) - return optional()(m_int_val); + return optional_t()(m_int_val); - __CPP_REDIS_LOG(1, "Reply is not an integer"); - return {}; + __CPP_REDIS_LOG(1, "Reply is not an integer"); + return {0}; } reply &