Skip to content

Commit

Permalink
More fixes from Dennis' remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
jfalcou committed Oct 15, 2023
1 parent 1a4e50a commit 40e1c55
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 24 deletions.
8 changes: 7 additions & 1 deletion include/eve/traits/overload/default_behaviors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ namespace eve
//! @struct constant
//! @brief CRTP base class giving an eve::callable the constant function semantic
//!
//! **Defined in Header**
//!
//! @code
//! #include <eve/module/core.hpp>
//! @endcode
//!
//! Constants functions in EVE are built using a very common pattern. Inheriting from eve::constant simplifies the
//! implementation of such eve::callable by just requiring your eve::callable type to implement a static `value`
//! member function that provides the constant value using two parameters:
Expand All @@ -89,7 +95,7 @@ namespace eve
//! @godbolt{doc/traits/callable_constant.cpp}
//! @}
//====================================================================================================================
template<typename Tag> struct constant : supports<Tag, conditional_options>
template<typename Tag> struct constant : supports<Tag, conditional_option>
{
struct behavior
{
Expand Down
42 changes: 27 additions & 15 deletions include/eve/traits/overload/protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ namespace eve
//! @concept callable
//! @brief **EVE** callable
//!
//! **Defined in Header**
//!
//! @code
//! #include <eve/module/core.hpp>
//! @endcode
//!
//! A type `T` satisfies eve::callable if and only if it is tagged as such manually.
//!
//! @tparam T T type for the @callable to check
Expand All @@ -41,6 +47,12 @@ namespace eve
//! @def EVE_CALLABLE_OBJECT_FROM
//! @brief Generate the generic function interface for any EVE-compatible @callable
//!
//! **Defined in Header**
//!
//! @code
//! #include <eve/module/core.hpp>
//! @endcode
//!
//! Use inside a @callable definition to generate the required EVE protocol of function's resolution based on type
//! and architecture informations.
//!
Expand Down Expand Up @@ -76,16 +88,13 @@ requires( requires { std::declval<TYPE>().call(EVE_FWD(args)...); })
{ \
return TYPE::deferred_call(eve::current_api, eve::detail::defaults<TYPE,Args...>(), EVE_FWD(args)...); \
} \
static EVE_FORCEINLINE decltype(auto) deferred_call(auto arch, auto&&...args) noexcept \
requires(requires { NAME(NS::adl_helper, arch, EVE_FWD(args)...); }) \
{ \
return NAME(NS::adl_helper, arch, EVE_FWD(args)...); \
} \
template<typename... Args> \
static EVE_FORCEINLINE decltype(auto) deferred_call(auto arch, Args&&...args) noexcept \
requires(!requires { NAME(NS::adl_helper, arch, EVE_FWD(args)...); }) \
{ \
return eve::detail::default_behavior<TYPE,Args...>::call(arch, EVE_FWD(args)...); \
if constexpr( requires { NAME(NS::adl_helper, arch, EVE_FWD(args)...); } ) \
return NAME(NS::adl_helper, arch, EVE_FWD(args)...); \
else \
return eve::detail::default_behavior<TYPE,Args...>::call(arch, EVE_FWD(args)...); \
} \
using callable_tag_type = TYPE \
/**/
Expand All @@ -96,6 +105,12 @@ using callable_tag_type = TYPE
//! @def EVE_CALLABLE_OBJECT
//! @brief Generate the generic function interface for an actual eve::callable
//!
//! **Defined in Header**
//!
//! @code
//! #include <eve/module/core.hpp>
//! @endcode
//!
//! Use inside a @callable definition to generate the required EVE protocol of function's resolution based on type
//! and architecture informations using overload from the `eve::detail` namespace.
//!
Expand Down Expand Up @@ -130,16 +145,13 @@ requires( requires { std::declval<TYPE>().call(EVE_FWD(args)...); })
{ \
return TYPE::deferred_call(eve::current_api, eve::detail::defaults<TYPE,Args...>(), EVE_FWD(args)...); \
} \
static EVE_FORCEINLINE decltype(auto) deferred_call(auto arch, auto&&...args) noexcept \
requires(requires { NAME(eve::detail::adl_helper, arch, EVE_FWD(args)...); }) \
{ \
return NAME(eve::detail::adl_helper, arch, EVE_FWD(args)...); \
} \
template<typename... Args> \
static EVE_FORCEINLINE decltype(auto) deferred_call(auto arch, Args&&...args) noexcept \
requires(!requires { NAME(eve::detail::adl_helper, arch, EVE_FWD(args)...); }) \
{ \
return eve::detail::default_behavior<TYPE,Args...>::call(arch, EVE_FWD(args)...); \
if constexpr( requires { NAME(eve::detail::adl_helper, arch, EVE_FWD(args)...); } ) \
return NAME(eve::detail::adl_helper, arch, EVE_FWD(args)...); \
else \
return eve::detail::default_behavior<TYPE,Args...>::call(arch, EVE_FWD(args)...); \
} \
using callable_tag_type = TYPE \
/**/
Expand All @@ -156,7 +168,7 @@ struct adl_helper_t {};
inline constexpr auto adl_helper = adl_helper_t {} \
/**/

// Flag a function to support delayed calls on given architecture
/// Flag a function to support delayed calls on given architecture
#define EVE_REQUIRES(ARCH) adl_helper_t const &, ARCH const &

// Register eve::detail as the deferred namespace by default
Expand Down
42 changes: 36 additions & 6 deletions include/eve/traits/overload/supports.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ namespace eve
//! @struct options
//! @brief Wrapper class around bundle of options passed to eve::callable
//!
//! **Defined in Header**
//!
//! @code
//! #include <eve/module/core.hpp>
//! @endcode
//!
//! eve::callable can be decorated with options. eve::options is used internally to gather all those options
//! in a @raberu settings instance for further processing.
//!
Expand Down Expand Up @@ -90,6 +96,12 @@ namespace eve
//! @var condition_key
//! @brief Keyword for retrieving conditionals decorator
//!
//! **Defined in Header**
//!
//! @code
//! #include <eve/module/core.hpp>
//! @endcode
//!
//! When a eve::decorated_callable is called with an option provided via eve::conditional, the value of the
//! conditional can be retrieved using eve::condition_key
//! @see eve::supports
Expand Down Expand Up @@ -144,6 +156,12 @@ namespace eve
//! @struct supports
//! @brief Helper class to aggregate options handlers
//!
//! **Defined in Header**
//!
//! @code
//! #include <eve/module/core.hpp>
//! @endcode
//!
//! eve::callable can be decorated with options. eve::supports is used to list all subset of options a given EVE
//! @callable is allowed to support and to handle the default values of such subsets.
//!
Expand Down Expand Up @@ -197,18 +215,24 @@ namespace eve
//====================================================================================================================
//! @addtogroup extensions
//! @{
//! @struct conditional_options
//! @struct conditional_option
//! @brief Option specification for decoration via conditional value and expressions
//!
//! eve::conditional_options is an option specification that can be used when defining a eve::callable type to make
//! **Defined in Header**
//!
//! @code
//! #include <eve/module/core.hpp>
//! @endcode
//!
//! eve::conditional_option is an option specification that can be used when defining a eve::callable type to make
//! it supports decoration via `bool`, eve::logical, any eve::conditional_expr or eve::relative_conditional_expr.
//!
//! @groupheader{Example}
//!
//! @godbolt{doc/traits/callable_supports.cpp}
//! @}
//====================================================================================================================
struct conditional_options
struct conditional_option
{
auto process_option(auto const& base, rbr::concepts::exactly<condition_key> auto opt) const
{
Expand Down Expand Up @@ -240,18 +264,24 @@ namespace eve
//====================================================================================================================
//! @addtogroup extensions
//! @{
//! @struct relative_conditional_options
//! @struct relative_conditional_option
//! @brief Option specification for decoration via relative conditional value and expressions
//!
//! eve::relative_conditional_options is an option specification that can be used when defining a eve::callable
//! **Defined in Header**
//!
//! @code
//! #include <eve/module/core.hpp>
//! @endcode
//!
//! eve::relative_conditional_option is an option specification that can be used when defining a eve::callable
//! type to make it supports decoration via any eve::relative_conditional_expr.
//!
//! @groupheader{Example}
//!
//! @godbolt{doc/traits/callable_supports.cpp}
//! @}
//====================================================================================================================
struct relative_conditional_options
struct relative_conditional_option
{
auto process_option(auto const& base, eve::relative_conditional_expr auto opt) const
{
Expand Down
4 changes: 2 additions & 2 deletions test/doc/traits/callable_supports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ namespace eve
{
// + supports give rules for decorator to use on a given callable and a default set of options
// + eve::conditional give the ability to pass a mask as a decoration.
struct func_t : supports<func_t, conditional_options>
struct func_t : supports<func_t, conditional_option>
{
// Note that decoration doesn't impact signature declaration
template<eve::integral_value T> auto call(T const&) -> T;
EVE_CALLABLE_OBJECT(func_t, func_);
} inline constexpr func;

struct other_func_t : supports<func_t, relative_conditional_options>
struct other_func_t : supports<func_t, relative_conditional_option>
{
// Note that decoration doesn't impact signature declaration
template<eve::integral_value T> auto call(T const&) -> T;
Expand Down

0 comments on commit 40e1c55

Please sign in to comment.