Loading src/sled/futures/future.h +1 −1 Original line number Diff line number Diff line Loading @@ -60,7 +60,7 @@ struct FutureData { void SetDefaultScheduler(TaskQueueBase *scheduler) noexcept; TaskQueueBase *GetDefaultScheduler() noexcept; template<typename T, typename FailureT = std::exception> template<typename T, typename FailureT = failure::DefaultException> class Future { static_assert(!std::is_same<T, void>::value, "Future<void, _> is not allowed. Use Future<bool, _> instead"); static_assert(!std::is_same<FailureT, void>::value, "Future<_, void> is not allowed. Use Future<_, bool> instead"); Loading src/sled/futures/future_test.cc +3 −0 Original line number Diff line number Diff line Loading @@ -113,6 +113,9 @@ TEST_SUITE("future") return 1; }); CHECK_FALSE(f2.IsFailed()); CHECK_EQ(std::string("test"), f2.FailureReason().what()); CHECK(f2.IsFailed()); auto f3 = sled::Future<std::string>::AsyncValue("11"); CHECK_EQ(f3.Result(), "11"); } Loading src/sled/futures/internal/failure_handling.h +32 −5 Original line number Diff line number Diff line Loading @@ -3,18 +3,38 @@ #pragma once #include "sled/any.h" #include "sled/nonstd/string_view.h" #include <string> namespace sled { namespace failure { template<typename FailureT> class DefaultException : std::exception { public: inline DefaultException() = default; inline DefaultException(const std::string &message) : message_(message) {} inline DefaultException(const char *message) : message_(message) {} ~DefaultException() noexcept override = default; const char *what() const noexcept override { return message_.c_str(); } private: std::string message_; }; template<typename FailureT, typename = typename std::enable_if<!std::is_constructible<FailureT, std::string>::value>::type> inline FailureT FailureFromString(std::string &&) FailureFromString(std::string &&str) { return FailureT(); } template<typename FailureT> template<typename FailureT, typename = typename std::enable_if<std::is_constructible<FailureT, const std::string &>::value>::type> inline FailureT FailureFromString(const std::string &str) { Loading @@ -24,9 +44,16 @@ FailureFromString(const std::string &str) template<> inline std::string FailureFromString<std::string>(std::string &&str) FailureFromString<std::string>(const std::string &str) { return str; } template<> inline DefaultException FailureFromString<DefaultException>(const std::string &str) { return std::move(str); return DefaultException(str); } }// namespace failure Loading src/sled/futures/internal/promise.h +2 −1 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ #pragma once #include "failure_handling.h" #include <memory> #include <type_traits> Loading @@ -10,7 +11,7 @@ namespace sled { template<typename T, typename FailureT> class Future; template<typename T, typename FailureT = std::exception> template<typename T, typename FailureT = failure::DefaultException> class Promise final { static_assert(!std::is_same<T, void>::value, "Promise<void, _> is not allowed. Use Promise<bool, _> instead"); static_assert(!std::is_same<FailureT, void>::value, Loading src/sled/numerics/int128.h 0 → 100644 +61 −0 Original line number Diff line number Diff line #ifndef SLED_NUMERICS_INT128_H #define SLED_NUMERICS_INT128_H #include <string> #pragma once namespace sled { class Int128 { constexpr Int128(int v); constexpr Int128(unsigned int v); constexpr Int128(long v); constexpr Int128(unsigned long v); constexpr Int128(long long v); constexpr Int128(unsigned long long v); constexpr Int128(const Int128 &v); Int128 &operator=(int v); Int128 &operator=(unsigned int v); Int128 &operator=(long v); Int128 &operator=(unsigned long v); Int128 &operator=(long long v); Int128 &operator=(unsigned long long v); Int128 &operator=(const Int128 &v); Int128 &operator+=(const Int128 &v); Int128 &operator-=(const Int128 &v); Int128 &operator*=(const Int128 &v); Int128 &operator/=(const Int128 &v); Int128 &operator%=(const Int128 &v); Int128 &operator++(int); Int128 &operator--(int); Int128 &operator&=(const Int128 &v); Int128 &operator|=(const Int128 &v); Int128 &operator^=(const Int128 &v); Int128 &operator<<=(int v); Int128 &operator>>=(int v); constexpr explicit operator bool() const; constexpr explicit operator char() const; constexpr explicit operator unsigned char() const; constexpr explicit operator short() const; constexpr explicit operator unsigned short() const; constexpr explicit operator int() const; constexpr explicit operator unsigned int() const; constexpr explicit operator long() const; constexpr explicit operator unsigned long() const; constexpr explicit operator long long() const; constexpr explicit operator unsigned long long() const; explicit operator float() const; explicit operator double() const; explicit operator long double() const; private: std::string ToString() const; uint64_t lo_; uint64_t hi_; }; }// namespace sled #endif// SLED_NUMERICS_INT128_H Loading
src/sled/futures/future.h +1 −1 Original line number Diff line number Diff line Loading @@ -60,7 +60,7 @@ struct FutureData { void SetDefaultScheduler(TaskQueueBase *scheduler) noexcept; TaskQueueBase *GetDefaultScheduler() noexcept; template<typename T, typename FailureT = std::exception> template<typename T, typename FailureT = failure::DefaultException> class Future { static_assert(!std::is_same<T, void>::value, "Future<void, _> is not allowed. Use Future<bool, _> instead"); static_assert(!std::is_same<FailureT, void>::value, "Future<_, void> is not allowed. Use Future<_, bool> instead"); Loading
src/sled/futures/future_test.cc +3 −0 Original line number Diff line number Diff line Loading @@ -113,6 +113,9 @@ TEST_SUITE("future") return 1; }); CHECK_FALSE(f2.IsFailed()); CHECK_EQ(std::string("test"), f2.FailureReason().what()); CHECK(f2.IsFailed()); auto f3 = sled::Future<std::string>::AsyncValue("11"); CHECK_EQ(f3.Result(), "11"); } Loading
src/sled/futures/internal/failure_handling.h +32 −5 Original line number Diff line number Diff line Loading @@ -3,18 +3,38 @@ #pragma once #include "sled/any.h" #include "sled/nonstd/string_view.h" #include <string> namespace sled { namespace failure { template<typename FailureT> class DefaultException : std::exception { public: inline DefaultException() = default; inline DefaultException(const std::string &message) : message_(message) {} inline DefaultException(const char *message) : message_(message) {} ~DefaultException() noexcept override = default; const char *what() const noexcept override { return message_.c_str(); } private: std::string message_; }; template<typename FailureT, typename = typename std::enable_if<!std::is_constructible<FailureT, std::string>::value>::type> inline FailureT FailureFromString(std::string &&) FailureFromString(std::string &&str) { return FailureT(); } template<typename FailureT> template<typename FailureT, typename = typename std::enable_if<std::is_constructible<FailureT, const std::string &>::value>::type> inline FailureT FailureFromString(const std::string &str) { Loading @@ -24,9 +44,16 @@ FailureFromString(const std::string &str) template<> inline std::string FailureFromString<std::string>(std::string &&str) FailureFromString<std::string>(const std::string &str) { return str; } template<> inline DefaultException FailureFromString<DefaultException>(const std::string &str) { return std::move(str); return DefaultException(str); } }// namespace failure Loading
src/sled/futures/internal/promise.h +2 −1 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ #pragma once #include "failure_handling.h" #include <memory> #include <type_traits> Loading @@ -10,7 +11,7 @@ namespace sled { template<typename T, typename FailureT> class Future; template<typename T, typename FailureT = std::exception> template<typename T, typename FailureT = failure::DefaultException> class Promise final { static_assert(!std::is_same<T, void>::value, "Promise<void, _> is not allowed. Use Promise<bool, _> instead"); static_assert(!std::is_same<FailureT, void>::value, Loading
src/sled/numerics/int128.h 0 → 100644 +61 −0 Original line number Diff line number Diff line #ifndef SLED_NUMERICS_INT128_H #define SLED_NUMERICS_INT128_H #include <string> #pragma once namespace sled { class Int128 { constexpr Int128(int v); constexpr Int128(unsigned int v); constexpr Int128(long v); constexpr Int128(unsigned long v); constexpr Int128(long long v); constexpr Int128(unsigned long long v); constexpr Int128(const Int128 &v); Int128 &operator=(int v); Int128 &operator=(unsigned int v); Int128 &operator=(long v); Int128 &operator=(unsigned long v); Int128 &operator=(long long v); Int128 &operator=(unsigned long long v); Int128 &operator=(const Int128 &v); Int128 &operator+=(const Int128 &v); Int128 &operator-=(const Int128 &v); Int128 &operator*=(const Int128 &v); Int128 &operator/=(const Int128 &v); Int128 &operator%=(const Int128 &v); Int128 &operator++(int); Int128 &operator--(int); Int128 &operator&=(const Int128 &v); Int128 &operator|=(const Int128 &v); Int128 &operator^=(const Int128 &v); Int128 &operator<<=(int v); Int128 &operator>>=(int v); constexpr explicit operator bool() const; constexpr explicit operator char() const; constexpr explicit operator unsigned char() const; constexpr explicit operator short() const; constexpr explicit operator unsigned short() const; constexpr explicit operator int() const; constexpr explicit operator unsigned int() const; constexpr explicit operator long() const; constexpr explicit operator unsigned long() const; constexpr explicit operator long long() const; constexpr explicit operator unsigned long long() const; explicit operator float() const; explicit operator double() const; explicit operator long double() const; private: std::string ToString() const; uint64_t lo_; uint64_t hi_; }; }// namespace sled #endif// SLED_NUMERICS_INT128_H