Skip to content

Commit

Permalink
✨ Complete rewrite internal span to use own personal implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePhD committed Nov 2, 2023
1 parent 75b470c commit ad64a17
Show file tree
Hide file tree
Showing 13 changed files with 1,182 additions and 1,819 deletions.
6 changes: 2 additions & 4 deletions include/ztd/idk/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
do { \
if (!(__VA_ARGS__)) { \
fprintf(stderr, "Assertion `%s` failed in " __FILE__ " line " \
ZTD_TOKEN_TO_STRING_I_(__LINE__) "\n", \
ZTD_TOKEN_TO_STRING(__LINE__) "\n", \
#__VA_ARGS__ ); \
exit(0xBF); \
} \
Expand Down Expand Up @@ -105,7 +105,7 @@
do { \
if (!(__VA_ARGS__)) { \
fprintf(stderr, "Assertion `%s` failed in " __FILE__ " line " \
ZTD_TOKEN_TO_STRING_I_(__LINE__) ": %s\n", \
ZTD_TOKEN_TO_STRING(__LINE__) ": %s\n", \
#__VA_ARGS__ , _MESSAGE); \
exit(0xBF); \
} \
Expand Down Expand Up @@ -147,6 +147,4 @@
/// terminate/exit (not abort).
#define ZTD_ASSERT_MESSAGE(_MESSAGE, ...) ZTD_ASSERT_MESSAGE_I_(_MESSAGE, __VA_ARGS__)

#include <ztd/epilogue.hpp>

#endif
168 changes: 168 additions & 0 deletions include/ztd/idk/assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,172 @@

#include <ztd/idk/assert.h>

// clang-format off
#if defined(ZTD_CONSTEXPR_ASSERT_USER)
#define ZTD_CONSTEXPR_ASSERT_I_(...) ZTD_CONSTEXPR_ASSERT_USER(__VA_ARGS__)
#else
#if ZTD_IS_ON(ZTD_CONSTEXPR_ASSERT_CHECKS)
#if ZTD_IS_ON(ZTD_STD_LIBRARY_IS_CONSTANT_EVALUATED)
#if ZTD_IS_ON(ZTD_EXCEPTIONS)
#include <exception>
#include <iostream>
#include <cstdlib>
#include <type_traits>

#define ZTD_CONSTEXPR_ASSERT_I_(...) \
do { \
if (!(__VA_ARGS__)) { \
if (::std::is_constant_evaluated()) { \
throw "Assertion " #__VA_ARGS__ "failed in " __FILE__ " line " ZTD_TOKEN_TO_STRING(__LINE__);\
} \
else { \
::std::cerr << "Assertion `" #__VA_ARGS__ "` failed in `" __FILE__ "` line " << \
__LINE__ << ::std::endl; \
::std::terminate(); \
} \
} \
} while (false)
#else
#include <exception>
#include <iostream>
#include <cstdlib>
#include <type_traits>

#define ZTD_CONSTEXPR_ASSERT_I_(...) \
do { \
if (!(__VA_ARGS__)) { \
if (::std::is_constant_evaluated()) { \
/* ?????*/; \
} \
else { \
::std::cerr << "Assertion `" #__VA_ARGS__ "` failed in `" __FILE__ "` line " << \
__LINE__ << ::std::endl; \
::std::terminate(); \
} \
} \
} while (false)
#endif
#else
#if ZTD_IS_ON(ZTD_EXCEPTIONS)
#include <cstdlib>

#define ZTD_CONSTEXPR_ASSERT_I_(...) \
do { \
if (!(__VA_ARGS__)) { \
throw "Assertion `" #__VA_ARGS__ "` failed in `" __FILE__ "` line " ZTD_TOKEN_TO_STRING(__LINE__);\
\
} \
} while (false)
#else
#include <cstdlib>

#define ZTD_CONSTEXPR_ASSERT_I_(...) \
do { \
if (!(__VA_ARGS__)) { \
/* ????? */; \
} \
} while (false)
#endif
#endif
#else
#define ZTD_CONSTEXPR_ASSERT_I_(...) \
do { \
if (false) { \
(void)(__VA_ARGS__); \
} \
} while (false)
#endif
#endif

#if defined(ZTD_CONSTEXPR_ASSERT_MESSAGE_USER)
#define ZTD_CONSTEXPR_ASSERT_MESSAGE_I_(...) ZTD_CONSTEXPR_ASSERT_MESSAGE_USER(__VA_ARGS__)
#else
#if ZTD_IS_ON(ZTD_CONSTEXPR_ASSERT_CHECKS)
#if ZTD_IS_ON(ZTD_STD_LIBRARY_IS_CONSTANT_EVALUATED)
#if ZTD_IS_ON(ZTD_EXCEPTIONS)
#include <exception>
#include <iostream>
#include <cstdlib>
#include <type_traits>

#define ZTD_CONSTEXPR_ASSERT_MESSAGE_I_(_MESSAGE, ...) \
do { \
if (!(__VA_ARGS__)) { \
if (::std::is_constant_evaluated()) { \
throw "Assertion `" #__VA_ARGS__ "1 failed in `" __FILE__ "` line " ZTD_TOKEN_TO_STRING(__LINE__) ": " _MESSAGE;\
} \
else { \
::std::cerr << "Assertion `" #__VA_ARGS__ "` failed in `" __FILE__ "` line " << __LINE__ << ": " \
<< _MESSAGE << ::std::endl; \
::std::terminate(); \
} \
} \
} while (false)
#else
#include <iostream>
#include <cstdlib>
#include <type_traits>

#define ZTD_CONSTEXPR_ASSERT_MESSAGE_I_(_MESSAGE, ...) \
do { \
if (!(__VA_ARGS__)) { \
if (::std::is_constant_evaluated()) { \
/* ????? */ \
} \
else { \
::std::cerr << "Assertion `" #__VA_ARGS__ "` failed in `" __FILE__ "` line " << __LINE__ << ": " \
<< _MESSAGE << ::std::endl; \
::std::terminate(); \
} \
} \
} while (false)
#endif
#endif
#else
#if ZTD_IS_ON(ZTD_EXCEPTIONS)
#define ZTD_CONSTEXPR_ASSERT_MESSAGE_I_(_MESSAGE, ...) \
do { \
if (!(__VA_ARGS__)) { \
throw "Assertion `" #__VA_ARGS__ "` failed in `" __FILE__ "` line " ZTD_TOKEN_TO_STRING(__LINE__) ": " _MESSAGE;\
} \
} while (false)
#else
#include <cstdlib>

#define ZTD_CONSTEXPR_ASSERT_MESSAGE_I_(_MESSAGE, ...) \
do { \
if (!(__VA_ARGS__)) { \
/* ???? */ \
(void)sizeof(_MESSAGE); \
} \
} while (false)
#endif
#endif
#endif

// clang-format on

//////
/// @brief A macro for asserting over a given (set of) conditions.
///
/// @param[in] ... The conditional expressions to check against.
///
/// @remarks The conditions must result in a value that is convertible to a boolean in a boolean context. This macro
/// does nothing when `ZTD_CONSTEXPR_ASSERT_CHECKS` is not detected. (It will still (void)-cast the used items, to prevent unused
/// warnings.) If the condition is not reached, this function will perform either a user-defined action or
/// terminate/exit (not abort).
#define ZTD_CONSTEXPR_ASSERT(...) ZTD_CONSTEXPR_ASSERT_I_(__VA_ARGS__)

//////
/// @brief A macro for asserting over a given (set of) conditions.
///
/// @param[in] _MESSAGE The message to pass through.
/// @param[in] ... The conditional expressions to check against.
///
/// @remarks The conditions must result in a value that is convertible to a boolean in a boolean context. This macro
/// does nothing when `ZTD_CONSTEXPR_ASSERT_CHECKS` is not detected. (It will still (void)-cast the used items, to prevent unused
/// warnings.) If the condition is not reached, this function will perform either a user-defined action or
/// terminate/exit (not abort).
#define ZTD_CONSTEXPR_ASSERT_MESSAGE(_MESSAGE, ...) ZTD_CONSTEXPR_ASSERT_MESSAGE_I_(_MESSAGE, __VA_ARGS__)

#endif
Loading

0 comments on commit ad64a17

Please sign in to comment.