diff --git a/src/sled/futures/future.h b/src/sled/futures/future.h index 139484a..a52bb07 100644 --- a/src/sled/futures/future.h +++ b/src/sled/futures/future.h @@ -60,7 +60,7 @@ struct FutureData { void SetDefaultScheduler(TaskQueueBase *scheduler) noexcept; TaskQueueBase *GetDefaultScheduler() noexcept; -template +template class Future { static_assert(!std::is_same::value, "Future is not allowed. Use Future instead"); static_assert(!std::is_same::value, "Future<_, void> is not allowed. Use Future<_, bool> instead"); diff --git a/src/sled/futures/future_test.cc b/src/sled/futures/future_test.cc index 92cecd7..0814648 100644 --- a/src/sled/futures/future_test.cc +++ b/src/sled/futures/future_test.cc @@ -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::AsyncValue("11"); CHECK_EQ(f3.Result(), "11"); } diff --git a/src/sled/futures/internal/failure_handling.h b/src/sled/futures/internal/failure_handling.h index 79e1491..fa90b8d 100644 --- a/src/sled/futures/internal/failure_handling.h +++ b/src/sled/futures/internal/failure_handling.h @@ -3,18 +3,38 @@ #pragma once #include "sled/any.h" +#include "sled/nonstd/string_view.h" #include namespace sled { namespace failure { -template + +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::value>::type> inline FailureT -FailureFromString(std::string &&) +FailureFromString(std::string &&str) { return FailureT(); } -template +template::value>::type> inline FailureT FailureFromString(const std::string &str) { @@ -24,9 +44,16 @@ FailureFromString(const std::string &str) template<> inline std::string -FailureFromString(std::string &&str) +FailureFromString(const std::string &str) { - return std::move(str); + return str; +} + +template<> +inline DefaultException +FailureFromString(const std::string &str) +{ + return DefaultException(str); } }// namespace failure diff --git a/src/sled/futures/internal/promise.h b/src/sled/futures/internal/promise.h index 79201ca..7252f85 100644 --- a/src/sled/futures/internal/promise.h +++ b/src/sled/futures/internal/promise.h @@ -3,6 +3,7 @@ #pragma once +#include "failure_handling.h" #include #include @@ -10,7 +11,7 @@ namespace sled { template class Future; -template +template class Promise final { static_assert(!std::is_same::value, "Promise is not allowed. Use Promise instead"); static_assert(!std::is_same::value, diff --git a/src/sled/numerics/int128.h b/src/sled/numerics/int128.h new file mode 100644 index 0000000..d184000 --- /dev/null +++ b/src/sled/numerics/int128.h @@ -0,0 +1,61 @@ +#ifndef SLED_NUMERICS_INT128_H +#define SLED_NUMERICS_INT128_H +#include + +#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 diff --git a/src/sled/units/timestamp.h b/src/sled/units/timestamp.h index 11f05d7..a454b74 100644 --- a/src/sled/units/timestamp.h +++ b/src/sled/units/timestamp.h @@ -108,7 +108,7 @@ public: } else if (IsMinusInfinity() || other.IsPlusInfinity()) { return TimeDelta::MinusInfinity(); } - return TimeDelta::Micros(us() - other.us()); + return TimeDelta::Nanos(ns() - other.ns()); } Timestamp &operator-=(const TimeDelta delta)