E.V.E
v2023.02.15
 
Loading...
Searching...
No Matches
eve::callable< Func, OptionsValues, Options > Struct Template Reference

CRTP base class defining an EVE's Callable Object. More...

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

Detailed Description

template<template< typename > class Func, typename OptionsValues, typename... Options>
struct eve::callable< Func, OptionsValues, Options >

Defined in Header

#include <eve/traits/overload.hpp>

All EVE Callable Object use a similar protocol to find and call proper architecture or type specific implementation. This protocol includes options checks and management and proper level of error reporting. eve::callable is the most general base class for defining such a Callable Object without having to manually handles all these details.

Template Parameters
FuncType of current Callable Object being implemented.
OptionsValuesType of stored options.
OptionsList of supported option specifications.

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
CRTP base class defining an EVE's Callable Object.
Definition default_behaviors.hpp:53
Wrapper for SIMD registers.
Definition wide.hpp:86

Public Member Functions

constexpr auto operator[] (O o) const
 Adds an option to current callable.
 
constexpr auto options () const
 Retrieves the current options' state, including processed default.
 

Friends

template<template< typename > class F2, typename OV2 , typename... O2>
constexpr bool operator== (callable const &, callable< F2, OV2, O2... > const &)
 Checks if two callable are instances of the same function.