Skip to content

Commit

Permalink
Cleanup consteval, constexpr void* cast macros
Browse files Browse the repository at this point in the history
  • Loading branch information
gracicot committed Oct 1, 2024
1 parent 64d74d8 commit 92256eb
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 44 deletions.
8 changes: 4 additions & 4 deletions include/kangaru/detail/ctti.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace kangaru::detail::ctti {
template<typename T>
inline KANGARU5_CONSTEVAL_IF_POSSIBLE auto raw_typed_signature() -> std::string_view {
inline KANGARU5_CONSTEVAL auto raw_typed_signature() -> std::string_view {
return KANGARU5_FUNCTION_SIGNATURE;
}

Expand All @@ -24,7 +24,7 @@ namespace kangaru::detail::ctti {

// TODO: Get stable type name on all compilers
template<typename T>
inline KANGARU5_CONSTEVAL_IF_POSSIBLE auto type_name_prefix_length() -> std::size_t {
inline KANGARU5_CONSTEVAL auto type_name_prefix_length() -> std::size_t {
using namespace std::literals;
auto const sig_prefix_trimmed = raw_typed_signature<T>().substr(signature_prefix_length);

Expand All @@ -40,7 +40,7 @@ namespace kangaru::detail::ctti {
}

template<typename T>
inline KANGARU5_CONSTEVAL_IF_POSSIBLE auto type_name() -> std::string_view {
inline KANGARU5_CONSTEVAL auto type_name() -> std::string_view {
auto const sig_prefix_trimmed = raw_typed_signature<T>().substr(type_name_prefix_length<T>());
return sig_prefix_trimmed.substr(
0,
Expand All @@ -53,7 +53,7 @@ namespace kangaru::detail::ctti {
struct type_id_for_result : std::integral_constant<std::size_t, detail::murmur::murmur64a(type_name<T>())> {};

template<typename T>
inline KANGARU5_CONSTEVAL_IF_POSSIBLE auto type_id_for() -> type_id_for_result<T> {
inline KANGARU5_CONSTEVAL auto type_id_for() -> type_id_for_result<T> {
return type_id_for_result<T>{};
}
}
Expand Down
8 changes: 4 additions & 4 deletions include/kangaru/detail/deducer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ namespace kangaru {

namespace detail::deducer {
template<typename T, typename F, std::size_t... before, std::size_t... after>
inline constexpr auto callable_with_nth_parameter_being_expand(std::index_sequence<before...>, std::index_sequence<after...>) -> bool {
inline KANGARU5_CONSTEVAL auto callable_with_nth_parameter_being_expand(std::index_sequence<before...>, std::index_sequence<after...>) -> bool {
return callable<
F,
detail::utility::expand<placeholder_deducer, before>...,
Expand All @@ -551,20 +551,20 @@ namespace kangaru {
}

template<typename T, typename F, std::size_t nth, std::size_t max>
inline constexpr auto callable_with_nth_parameter_being() -> bool {
inline KANGARU5_CONSTEVAL auto callable_with_nth_parameter_being() -> bool {
return callable_with_nth_parameter_being_expand<T, F>(std::make_index_sequence<nth>{}, std::make_index_sequence<max - nth - 1>{});
}

template<typename F, std::size_t nth, std::size_t max>
inline constexpr auto is_nth_parameter_prvalue() -> bool {
inline KANGARU5_CONSTEVAL auto is_nth_parameter_prvalue() -> bool {
return (
not callable_with_nth_parameter_being<ambiguous_prvalue_deducer, F, nth, max>()
and callable_with_nth_parameter_being<ambiguous_overloaded_reference_deducer, F, nth, max>()
);
}

template<typename T, typename F, std::size_t nth, std::size_t max>
inline constexpr auto reference_kind_for_nth_parameter() -> reference_kind {
inline KANGARU5_CONSTEVAL auto reference_kind_for_nth_parameter() -> reference_kind {
if constexpr (is_nth_parameter_prvalue<F, nth, max>()) {
return reference_kind::none;
} else {
Expand Down
96 changes: 64 additions & 32 deletions include/kangaru/detail/define.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,102 @@
#define KANGARU5_DETAIL_DEFINE_HPP

#if defined(_MSC_VER) && !defined(__clang__)
#define KANGARU5_IS_MSVC() 1
#define KANGARU5_IS_MSVC() 1
#else
#define KANGARU5_IS_MSVC() 0
#define KANGARU5_IS_MSVC() 0
#endif

#if defined(__GNUC__) && !defined(__clang__)
#define KANGARU5_IS_GNU() 1
#define KANGARU5_IS_GNU() 1
#else
#define KANGARU5_IS_GNU() 0
#define KANGARU5_IS_GNU() 0
#endif

#if defined(__clang__)
#define KANGARU5_IS_CLANG() 1
#define KANGARU5_IS_CLANG() 1
#else
#define KANGARU5_IS_CLANG() 0
#endif

#if KANGARU5_IS_MSVC() == 1
#define KANGARU5_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
#else
#define KANGARU5_NO_UNIQUE_ADDRESS [[no_unique_address]]
#endif

#if KANGARU5_IS_MSVC() == 1
#define KANGARU5_FUNCTION_SIGNATURE __FUNCSIG__
#else
#define KANGARU5_FUNCTION_SIGNATURE __PRETTY_FUNCTION__
#define KANGARU5_IS_CLANG() 0
#endif

#define KANGARU5_FWD(...) static_cast<decltype(__VA_ARGS__)&&>(__VA_ARGS__)
#define KANGARU5_CONSTRUCTOR_T(...) decltype(::kangaru::constructor<__VA_ARGS__>())

#if KANGARU5_IS_CLANG() == 1
#define KANGARU5_INLINE [[gnu::always_inline]]
#define KANGARU5_RVALUE_AMBIGUOUS() 0
#define KANGARU5_LVALUE_CONST_AMBIGUOUS() 1
#define KANGARU5_NO_UNIQUE_ADDRESS [[no_unique_address]]
#define KANGARU5_INLINE [[gnu::always_inline]]
#define KANGARU5_RVALUE_AMBIGUOUS() 0
#define KANGARU5_LVALUE_CONST_AMBIGUOUS() 1
#define KANGARU5_FUNCTION_SIGNATURE __PRETTY_FUNCTION__
#endif

#if KANGARU5_IS_GNU() == 1
#define KANGARU5_INLINE [[gnu::always_inline]]
#define KANGARU5_RVALUE_AMBIGUOUS() 1
#define KANGARU5_LVALUE_CONST_AMBIGUOUS() 0
#define KANGARU5_NO_UNIQUE_ADDRESS [[no_unique_address]]
#define KANGARU5_INLINE [[gnu::always_inline]]
#define KANGARU5_RVALUE_AMBIGUOUS() 1
#define KANGARU5_LVALUE_CONST_AMBIGUOUS() 0
#define KANGARU5_FUNCTION_SIGNATURE __PRETTY_FUNCTION__
#endif

#if KANGARU5_IS_MSVC() == 1
#define KANGARU5_INLINE [[msvc::forceinline]]
#define KANGARU5_RVALUE_AMBIGUOUS() 0
#define KANGARU5_LVALUE_CONST_AMBIGUOUS() 1
#define KANGARU5_FUNCTION_SIGNATURE __FUNCSIG__
#define KANGARU5_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
#define KANGARU5_INLINE [[msvc::forceinline]]
#define KANGARU5_RVALUE_AMBIGUOUS() 0
#define KANGARU5_LVALUE_CONST_AMBIGUOUS() 1
#endif

#if KANGARU5_IS_CLANG() == 1
#if __clang_major__ < 14
#define KANGARU5_CONSTEVAL_SUPPORTED() 0
#else
#define KANGARU5_CONSTEVAL_SUPPORTED() 1
#endif
#else
#define KANGARU5_CONSTEVAL_SUPPORTED() 1
#endif

#if KANGARU5_IS_CLANG() == 1
#if __clang_major__ >= 17
#define KANGARU5_CONSTEXPR_VOIDSTAR_CAST_SUPPORTED() 1
#else
#define KANGARU5_CONSTEXPR_VOIDSTAR_CAST_SUPPORTED() 0
#endif
#elif KANGARU5_IS_GNU() == 1
#if __GNUC__ >= 14
#define KANGARU5_CONSTEXPR_VOIDSTAR_CAST_SUPPORTED() 1
#else
#define KANGARU5_CONSTEXPR_VOIDSTAR_CAST_SUPPORTED() 0
#endif
#elif KANGARU5_IS_MSVC() == 1
#define KANGARU5_CONSTEXPR_VOIDSTAR_CAST_SUPPORTED() 0
#elif __cpp_constexpr >= 202306L // C++26 constexpr
#define KANGARU5_CONSTEXPR_VOIDSTAR_CAST_SUPPORTED() 1
#else
#define KANGARU5_CONSTEXPR_VOIDSTAR_CAST_SUPPORTED() 0
#endif

#undef KANGARU5_IS_MSVC
#undef KANGARU5_IS_GNU
#undef KANGARU5_IS_CLANG

#define KANGARU5_CONSTEVAL_IF_POSSIBLE consteval
#if KANGARU5_CONSTEVAL_SUPPORTED() == 1
#define KANGARU5_CONSTEVAL consteval
#else
#define KANGARU5_CONSTEVAL constexpr
#endif

#define KANGARU5_UNSAFE /* left undefined */
#define KANGARU5_UNSAFE_BLOCK /* left undefined */

#if __cpp_constexpr >= 202306L // C++26 constexpr
#define KANGARU5_CONSTEXPR_VOIDSTAR constexpr
#if KANGARU5_CONSTEXPR_VOIDSTAR_CAST_SUPPORTED() == 1
#define KANGARU5_CONSTEXPR_VOIDSTAR constexpr
#else
#define KANGARU5_CONSTEXPR_VOIDSTAR
#define KANGARU5_CONSTEXPR_VOIDSTAR
#endif

#undef KANGARU5_CONSTEVAL_SUPPORTED
#undef KANGARU5_CONSTEXPR_VOIDSTAR_CAST

#else
#error "A previous header seem to have leaked macros"
#error "A previous header seem to have leaked macros"
#endif // KANGARU5_DETAIL_DEFINE_HPP
8 changes: 4 additions & 4 deletions include/kangaru/detail/recursive_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ namespace kangaru {

template<typename Type, movable_object MakeInjector>
struct basic_placeholder_construct_except {
constexpr basic_placeholder_construct_except() requires std::default_initializable<MakeInjector> = default;
KANGARU5_CONSTEVAL basic_placeholder_construct_except() requires std::default_initializable<MakeInjector> = default;

explicit constexpr basic_placeholder_construct_except(MakeInjector make_injector) noexcept :
explicit KANGARU5_CONSTEVAL basic_placeholder_construct_except(MakeInjector make_injector) noexcept :
make_injector{std::move(make_injector)} {}

template<typename T>
Expand Down Expand Up @@ -170,9 +170,9 @@ namespace kangaru {

template<movable_object MakeInjector>
struct basic_placeholder_construct {
constexpr basic_placeholder_construct() requires std::default_initializable<MakeInjector> = default;
KANGARU5_CONSTEVAL basic_placeholder_construct() requires std::default_initializable<MakeInjector> = default;

explicit constexpr basic_placeholder_construct(MakeInjector make_injector) noexcept :
explicit KANGARU5_CONSTEVAL basic_placeholder_construct(MakeInjector make_injector) noexcept :
make_injector{std::move(make_injector)} {}

template<typename T>
Expand Down

0 comments on commit 92256eb

Please sign in to comment.