E.V.E
v2023.02.15
 
Loading...
Searching...
No Matches

◆ EVE_CALLABLE_OBJECT

#define EVE_CALLABLE_OBJECT ( TYPE,
NAME )

#include <eve/traits/overload/protocol.hpp>

Value:
template<typename... Args> \
static EVE_FORCEINLINE constexpr auto deferred_call(auto arch, Args&&...args) noexcept \
-> decltype(NAME(eve::detail::adl_helper, arch, EVE_FWD(args)...)) \
{ \
return NAME(eve::detail::adl_helper, arch, EVE_FWD(args)...); \
} \
using callable_tag_type = TYPE \

Defined in Header

#include <eve/module/core.hpp>

Use inside a Callable Object definition to generate the required EVE protocol of function's resolution based on type and architecture informations using overload from the eve::detail namespace.

Warning
EVE_CALLABLE_OBJECT is mostly used for EVE Callable Object definition. If you want to use EVE's overload facility for your own library, use EVE_CALLABLE_OBJECT_FROM.
Parameters
TYPECurrent Callable Object type
NAMEFunction identifier for overloads. Calls to eve::detail::NAME are supposed to succeed.

Usage

EVE_CALLABLE_OBJECT generates the expected code for defining a EVE Callable Object. EVE Callable Object are function object which supports decorators and use an external function to specify its implementation.

EVE_CALLABLE_OBJECT relies on its enclosing type to provide at least one declaration of a member function named call which represent the expected prototype of the function object, including potential constraints, and its associated return type. EVE_CALLABLE_OBJECT also relies on the existence of an appropriate number of function overloads named NAME defined in the eve::detail namespace. Those function contains the implementation of the Callable Object overload for each pre-defined function.

Example

#include <iostream>
#include <type_traits>
#include <eve/traits/overload.hpp>
#include <eve/wide.hpp>
namespace eve
{
template<typename Options>
struct func_t : callable<func_t, Options>
{
// operator() are defined here to maximize quality of error message. They all use EVE_DISPATCH_CALL at some point.
template<eve::integral_value T>
EVE_FORCEINLINE T operator()(T v) const { return EVE_DISPATCH_CALL(v); }
EVE_FORCEINLINE double operator()(double v) const { return EVE_DISPATCH_CALL(v); }
EVE_FORCEINLINE void operator()(float) const = delete;
// This ties the function object to the overload set
EVE_CALLABLE_OBJECT(func_t, func_);
};
// Build the callable object from the function object type
inline constexpr auto func = functor<func_t>;
};
// As func_t used EVE_CALLABLE_OBJECT, we should write overloads in eve::detail
namespace eve::detail
{
auto func_(EVE_REQUIRES(cpu_), eve::callable_options auto const&, eve::integral_value auto x) { return x*x; }
auto func_(EVE_REQUIRES(cpu_), eve::callable_options auto const&, double x) { return 1./x; }
}
int main()
{
std::cout << eve::func(8) << "\n";
std::cout << eve::func(eve::wide<short>{77}) << "\n";
std::cout << eve::func(25.) << "\n";
std::cout << "Is func(double) supported : "
<< std::boolalpha << std::is_invocable_v<eve::tag_t<eve::func>, double>
<< "\n";
std::cout << "Is func(float) supported : "
<< std::boolalpha << std::is_invocable_v<eve::tag_t<eve::func>, float>
<< "\n";
std::cout << "Is func(wide<float>) supported: "
<< std::boolalpha << std::is_invocable_v<eve::tag_t<eve::func>, eve::wide<float>>
<< "\n";
}
The concept integral_value<T> is satisfied if and only if T satisfies eve::value and the element type...
Definition value.hpp:51
#define EVE_CALLABLE_OBJECT(TYPE, NAME)
Generate the generic function interface for an actual eve::callable.
Definition protocol.hpp:131
constexpr auto functor
EVE's Callable Object generator.
Definition supports.hpp:89
#define EVE_REQUIRES(ARCH)
Flag a function to support delayed calls on given architecture.
Definition protocol.hpp:171
#define EVE_DISPATCH_CALL(...)
Generate the proper call to current EVE's Callable Object implementation.
Definition protocol.hpp:148
EVE Main Namespace.
Definition abi.hpp:18
Wrapper for SIMD registers.
Definition wide.hpp:70