diff options
author | crupest <crupest@outlook.com> | 2024-02-08 15:12:29 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2024-02-08 15:12:29 +0800 |
commit | f3af6c7e5b46f4209a4981e5d7be217368f40b15 (patch) | |
tree | e932747ad91a718abb667a6170b21f1521a04d1e /include/cru/common | |
parent | bfe23251a54b036abef9241ba0994c9e51db25b2 (diff) | |
download | cru-f3af6c7e5b46f4209a4981e5d7be217368f40b15.tar.gz cru-f3af6c7e5b46f4209a4981e5d7be217368f40b15.tar.bz2 cru-f3af6c7e5b46f4209a4981e5d7be217368f40b15.zip |
Get rid of GSL.
Diffstat (limited to 'include/cru/common')
-rw-r--r-- | include/cru/common/Base.h | 22 | ||||
-rw-r--r-- | include/cru/common/Event.h | 3 |
2 files changed, 20 insertions, 5 deletions
diff --git a/include/cru/common/Base.h b/include/cru/common/Base.h index 34faf779..8a6a7634 100644 --- a/include/cru/common/Base.h +++ b/include/cru/common/Base.h @@ -1,5 +1,10 @@ #pragma once -#include "PreConfig.h" // IWYU pragma: keep +#include "PreConfig.h" // IWYU pragma: keep + +#include <cassert> +#include <cstddef> +#include <functional> +#include <memory> #ifdef CRU_PLATFORM_WINDOWS #ifdef CRU_BASE_EXPORT_API @@ -11,8 +16,6 @@ #define CRU_BASE_API #endif -#include <gsl/gsl> - #define CRU_UNUSED(entity) static_cast<void>(entity); #define CRU__CONCAT(a, b) a##b @@ -83,7 +86,18 @@ struct CRU_BASE_API Interface { [[noreturn]] void CRU_BASE_API UnreachableCode(); -using Index = gsl::index; +using Index = std::ptrdiff_t; + +inline void Expects(bool condition) { assert(condition); } +inline void Ensures(bool condition) { assert(condition); } +template <typename T> +inline void Expects(const std::shared_ptr<T>& ptr) { + assert(ptr != nullptr); +} +template <typename T> +inline void Ensures(const std::shared_ptr<T>& ptr) { + assert(ptr != nullptr); +} // https://www.boost.org/doc/libs/1_54_0/doc/html/hash/reference.html#boost.hash_combine template <class T> diff --git a/include/cru/common/Event.h b/include/cru/common/Event.h index 14d68833..18d2c570 100644 --- a/include/cru/common/Event.h +++ b/include/cru/common/Event.h @@ -4,6 +4,7 @@ #include "SelfResolvable.h" #include <algorithm> +#include <cassert> #include <functional> #include <memory> #include <utility> @@ -235,7 +236,7 @@ class EventRevokerGuard { EventRevoker Get() { // revoker is only null when this is moved // you shouldn't use a moved instance - Expects(revoker_); + assert(revoker_); return *revoker_; } |