#ifndef _EXOPT_H #define _EXOPT_H #define _EO__OPT_OLD_ASSUME //XXX: __attribute__((gnu::assume(X))) fails to build #define _EXOPT_INTERNAL_PREFIX _exopt__ #ifdef __cplusplus # define _exopt__cpp 1 # define _exopt__c 1 extern "C" { #else # define _exopt__cpp 0 # define _exopt__c 1 #endif #define _EO_PASTE_(x,y) x##y #define _EO_PASTE(x,y) _EO_PASTE_(x,y) #define _EO(X) _EO_PASTE(_EXOPT_INTERNAL_PREFIX, X) #define _exopt__internal __attribute__((visibility("internal"))) #define _exopt__readonly __attribute__((__pure__)) #define _exopt__pure __attribute__((__const__)) #ifdef _EO__OPT_OLD_ASSUME # define _EO_ASSUME(X) ({ if(! (X)) __builtin_unreachable(); }) #endif #define _EO_NOTHING #if _EO(cpp) # ifndef _EO_ASSUME # define _EO_ASSUME(X) [[gnu::assume(X)]] # endif # define _exopt__restrict __restrict__ #define _EO_CTORS_BASIC_W(N, constexpr, noexcept, ...) \ constexpr N(N const&) noexcept __VA_ARGS__; \ constexpr N(N &&) noexcept __VA_ARGS__; \ constexpr N & operator=(N const&) noexcept __VA_ARGS__; \ constexpr N & operator=(N &&) noexcept __VA_ARGS__ #define _EO_CTORS_BASIC(...) _EO_CTORS_BASIC_W(__VA_ARGS__, _EO_NOTHING, _EO_NOTHING, _EO_NOTHING) #define _EO_CTORS_BASIC_DEFAULT(...) _EO_CTORS_BASIC(__VA_ARGS__, _EO_NOTHING, _EO_NOTHING, = default) #define _EO_CTORS_DEFAULT_BASIC_W(N, constexpr, noexcept, ...) \ constexpr N(N const&) noexcept = default; \ constexpr N(N &&) noexcept = default; \ constexpr N & operator=(N const&) noexcept = default; \ constexpr N & operator=(N &&) noexcept = default #define _EO_CTORS_DEFAULT_BASIC(N) _EO_CTORS_DEFAULT_BASIC_W(N, constexpr, _EO_NOTHING, _EO_NOTHING) #define _EO_CTORS_DEFAULT_BASIC_RT(N) _EO_CTORS_DEFAULT_BASIC_W(N, _EO_NOTHING, _EO_NOTHING, _EO_NOTHING) #define _EO_CTORS_DEFAULT_BASIC_NE_W(N, C) _EO_CTORS_DEFAULT_BASIC_W(N, C, noexcept, _EO_NOTHING) #define _EO_CTORS_DEFAULT_BASIC_NE(N) _EO_CTORS_DEFAULT_BASIC_W(N, constexpr, noexcept, _EO_NOTHING) #define _EO_CTORS_DEFAULT_BASIC_NE_RT(N) _EO_CTORS_DEFAULT_BASIC_W(N, _EO_NOTHING, noexcept, _EO_NOTHING) #define _EO_CLASS_DEFAULT_(N, ...) N #define _EO_CLASS_DEFAULT_2(_, N, ...) N #define _EO_CLASS_DEFAULT_3(_, __, N, ...) N #define _EO_CLASS_DEFAULT_4(_, __, ___, N, ...) N #define _EO_CLASS_DEFAULT_3REST(_, __, ___, ...) __VA_ARGS__ #define _EO_CLASS_DEFAULT_4REST(_, __, ___, ____, ...) __VA_ARGS__ // _EO_CLASS_DEFINE(NAME, [constexpr], [noexcept], [virtual], [=default]) #define _EO_CLASS_DEFINE(...) _EO_CTORS_BASIC(__VA_ARGS__); \ _EO_CLASS_DEFAULT_4(__VA_ARGS__, _EO_NOTHING, _EO_NOTHING, _EO_NOTHING, _EO_NOTHING, _EO_NOTHING) _EO_CLASS_DEFAULT_2(__VA_ARGS__, _EO_NOTHING, _EO_NOTHING) ~ _EO_CLASS_DEFAULT_(__VA_ARGS__, _EO_NOTHING)() _EO_CLASS_DEFAULT_3(__VA_ARGS__, _EO_NOTHING, _EO_NOTHING, _EO_NOTHING) _EO_CLASS_DEFAULT_4REST(__VA_ARGS__, _EO_NOTHING, _EO_NOTHING, _EO_NOTHING, _EO_NOTHING, _EO_NOTHING) #else # ifndef _EO_ASSUME # define _EO_ASSUME(X) __attribute__((assume(X))) # endif # define _exopt__restrict restrict #endif #ifdef __cplusplus } #endif #endif /* _EXOPT_H */