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

◆ EVE_CALLABLE_OBJECT_FROM

#define EVE_CALLABLE_OBJECT_FROM ( NS,
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(NS::adl_helper, arch, EVE_FWD(args)...)) \
{ \
return NAME( NS::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.

Parameters
NSNamespace in which specialization of the Callable Object will be found. This namespace must have been registered via EVE_CALLABLE_NAMESPACE.
TYPECurrent Callable Object type
NAMEFunction identifier for overloads. Calls to NS::NAME are supposed to succeed.
See also
EVE_CALLABLE_OBJECT
EVE_CALLABLE_NAMESPACE

Usage

EVE_CALLABLE_OBJECT_FROM 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_FROM 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 NS 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>
// Register my_lib::impl as a proper callable namespace
namespace my_lib::impl { EVE_CALLABLE_NAMESPACE(); }
// EVE_CALLABLE_OBJECT_FROM helps defining your own EVE-like callable in your own library
namespace my_lib
{
template<typename Options>
struct func_t : eve::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_FROM(my_lib::impl, func_t, func_);
};
// Build the callable object from the function object type
inline constexpr auto func = eve::functor<func_t>;
// As func_t used EVE_CALLABLE_OBJECT_FROM, we can write overloads in this namespace
namespace impl
{
auto func_(EVE_REQUIRES(eve::cpu_), eve::callable_options auto const&, eve::integral_value auto x) { return x*x; }
auto func_(EVE_REQUIRES(eve::cpu_), eve::callable_options auto const&, double x) { return 1./x; }
}
}
int main()
{
std::cout << my_lib::func(8) << "\n";
std::cout << my_lib::func(eve::wide<short>{77}) << "\n";
std::cout << my_lib::func(25.) << "\n";
std::cout << "Is func(double) supported : "
<< std::boolalpha << std::is_invocable_v<eve::tag_t<my_lib::func>, double>
<< "\n";
std::cout << "Is func(float) supported : "
<< std::boolalpha << std::is_invocable_v<eve::tag_t<my_lib::func>, float>
<< "\n";
std::cout << "Is func(wide<float>) supported: "
<< std::boolalpha << std::is_invocable_v<eve::tag_t<my_lib::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_FROM(NS, TYPE, NAME)
Generate the generic function interface for any EVE-compatible Callable Object
Definition protocol.hpp:83
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_CALLABLE_NAMESPACE()
Register a namespace as suitable for containing eve::callable overloads.
Definition protocol.hpp:159
#define EVE_DISPATCH_CALL(...)
Generate the proper call to current EVE's Callable Object implementation.
Definition protocol.hpp:148
CRTP base class defining an EVE's Callable Object.
Definition default_behaviors.hpp:53
Wrapper for SIMD registers.
Definition wide.hpp:70