#pragma once #include <type_traits> namespace sprawl { namespace type_traits { #define SPRAWL_COMMA , #define CREATE_OPERATOR_TEST(NAME, OPERATOR) \ namespace detail { \ template<class T, class = decltype(std::declval<T>()OPERATOR)> \ std::true_type Has ## NAME ## Test(const T&); \ std::false_type Has ## NAME ## Test(...); \ } \ template<class T> using Has ## NAME = decltype(detail::Has ## NAME ## Test(std::declval<T>())) #define CREATE_PRE_OPERATOR_TEST(NAME, OPERATOR) \ namespace detail { \ template<class T, class = decltype(OPERATOR std::declval<T>())> \ std::true_type Has ## NAME ## Test(const T&); \ std::false_type Has ## NAME ## Test(...); \ } \ template<class T> using Has ## NAME = decltype(detail::Has ## NAME ## Test(std::declval<T>())) #define CREATE_FUNCTION_TEST(NAME, FUNCTION) \ namespace detail { \ template<class T, class = decltype(std::declval<T>().FUNCTION)> \ std::true_type Has ## NAME ## Test(const T&); \ std::false_type Has ## NAME ## Test(...); \ } \ template<class T> using Has ## NAME = decltype(detail::Has ## NAME ## Test(std::declval<T>())) CREATE_OPERATOR_TEST(EmptyOperatorParens, ()); CREATE_OPERATOR_TEST(IndexOperator, [0]); CREATE_OPERATOR_TEST(PostIncrement, ++); CREATE_OPERATOR_TEST(PostDecrement, --); CREATE_PRE_OPERATOR_TEST(PreIncrement, ++); CREATE_PRE_OPERATOR_TEST(PreDecrement, --); CREATE_PRE_OPERATOR_TEST(Dereference, *); CREATE_PRE_OPERATOR_TEST(AddressOf, &); CREATE_PRE_OPERATOR_TEST(UnaryPlus, +); CREATE_PRE_OPERATOR_TEST(UneryMinus, -); CREATE_OPERATOR_TEST(SameTypeAdditionOperator, +std::declval<T>()); CREATE_OPERATOR_TEST(SameTypeSubtractionOperator, - std::declval<T>()); CREATE_OPERATOR_TEST(SameTypeMultiplicationOperator, * std::declval<T>()); CREATE_OPERATOR_TEST(SameTypeDivisionOperator, / std::declval<T>()); CREATE_OPERATOR_TEST(SameTypeModuloOperator, % std::declval<T>()); CREATE_OPERATOR_TEST(SameTypeAdditionAssignmentOperator, += std::declval<T>()); CREATE_OPERATOR_TEST(SameTypeSubtractionAssignmentOperator, -= std::declval<T>()); CREATE_OPERATOR_TEST(SameTypeMultiplicationAssignmentOperator, *= std::declval<T>()); CREATE_OPERATOR_TEST(SameTypeDivisionAssignmentOperator, /= std::declval<T>()); CREATE_OPERATOR_TEST(SameTypeModuloAssignmentOperator, %= std::declval<T>()); CREATE_OPERATOR_TEST(SameTypeEqualityOperator, == std::declval<T>()); CREATE_OPERATOR_TEST(SameTypeInequalityOperator, != std::declval<T>()); CREATE_OPERATOR_TEST(SameTypeGreaterThanOperator, > std::declval<T>()); CREATE_OPERATOR_TEST(SameTypeLessThanOperator, < std::declval<T>()); CREATE_OPERATOR_TEST(SameTypeGreaterOrEqualOperator, >= std::declval<T>()); CREATE_OPERATOR_TEST(SameTypeLessOrEqualOperator, <= std::declval<T>()); CREATE_PRE_OPERATOR_TEST(LogicalNotOperator, !); CREATE_OPERATOR_TEST(SameTypeLogicalAnd, && std::declval<T>()); CREATE_OPERATOR_TEST(SameTypeLogicalOr, || std::declval<T>()); CREATE_PRE_OPERATOR_TEST(BitwiseNotOperator, ~); CREATE_OPERATOR_TEST(SameTypeBitwiseAnd, &std::declval<T>()); CREATE_OPERATOR_TEST(SameTypeBitwiseOr, | std::declval<T>()); CREATE_OPERATOR_TEST(SameTypeBitwiseXor, ^ std::declval<T>()); CREATE_OPERATOR_TEST(SameTypeLeftShiftOperator, << std::declval<T>()); CREATE_OPERATOR_TEST(SameTypeRightShiftOperator, >> std::declval<T>()); CREATE_OPERATOR_TEST(SameTypeBitwiseAndAssignment, &= std::declval<T>()); CREATE_OPERATOR_TEST(SameTypeBitwiseOrAssignment, |= std::declval<T>()); CREATE_OPERATOR_TEST(SameTypeBitwiseXorAssignment, ^= std::declval<T>()); CREATE_OPERATOR_TEST(SameTypeLeftShiftOperatorAssignment, <<= std::declval<T>()); CREATE_OPERATOR_TEST(SameTypeRightShiftOperatorAssignment, >>= std::declval<T>()); CREATE_OPERATOR_TEST(SameTypeCommaOperator, SPRAWL_COMMA std::declval<T>()); CREATE_OPERATOR_TEST(CopyAssignmentOperator, = std::declval<T>()); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 23398 | ququlala | "Forking branch Mainline of shadauxcat-libsprawl to ququlala-libsprawl." | ||
//guest/ShadauxCat/Sprawl/Mainline/common/type_traits.hpp | |||||
#3 | 16378 | ShadauxCat |
New exception framework, phase one. Added new class, ErrorState, for handling errors when exceptions are disabled. When exceptions are enabled, ErrorState<T> is an alias for T. When they're disabled, ErrorState<T> additionally encodes an error code, and will have junk data (and probably a crash) if an error is returned and not checked before the data is used. ErrorState<T> is implicitly convertible to and from T, so applications that don't care about errors can code like they don't exist... Phase two will involve overloading operators on ErrorState so that things that return ErrorState can still function as much as possible like they do when exceptions are enabled. #review-16379 |
||
#2 | 16173 | ShadauxCat |
Fixed clang compile error (which should have been a windows error, too, bad windows.) #review-16174 |
||
#1 | 16171 | ShadauxCat |
- Created type traits header including macros to make checks for types having any operator or member function, and seeded it with every operator operating on the same type. For function and/or type combinations not already handled, creating a new type traits struct is just a single line of code. - Updated coroutine to use the new type traits header and removed the explicit operator() check - Added alternative to SPRAWL_THROW_EXCEPTION - SPRAWL_THROW_EXCEPTION_OR_ABORT, which as it sounds, will either throw the exception if exceptions are enabled, otherwise will print the message and abort. This is for cases where returning a value reliably isn't possible, such as in constructors or code that returns a template type that may not be default constructible. - Added a layer of safety around coroutines; trying to call the various functions that pause the current coroutine will now throw an exception (if enabled) or abort (if not) if you try to call the wrong pause function (i.e., calling an empty yield() on a coroutine that's supposed to return a value) - Added ability to determine what type a CoroutineBase object actually is underneath - Added function in logging to flush one specific category instead of flushing everything #review-16172 |