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

CRTP base class giving an EVE's Callable Object the constant function semantic. More...

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

Detailed Description

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

Defined in Header

#include <eve/traits/overload.hpp>

Constants functions in EVE are built using a very common pattern. Inheriting from eve::constant_callable 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:

  • an eve::options pack containing potential decorators passed to the constant.
  • an eve::as instance to specify the translated element type of the output.

Constant functions in EVE also supports masking, which is directly implemented in eve::constant_callable.

Note
The deferred overload named in the EVE_CALLABLE_OBJECT macro process is still available if an architecture specific implementation of any given constant is required.
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
{
// Constant generations functions have a precise behavior so they can be defined using the
// constant_callable scaffolding that enables this.
// Note that constant_callable provides support for conditional out of the box.
template<typename Options>
struct some_pi_t : constant_callable<some_pi_t, Options>
{
// A constant must provide a value() static member with up to two parameters:
// * an eve::as instance to specify the output type
// * an optional eve::options containing potential decorators passed to the constant
template<typename T>
static EVE_FORCEINLINE T value(eve::as<T> const&, auto) { return static_cast<T>(3.14159216); }
// Supported function calls are still required
template<eve::floating_value T>
EVE_FORCEINLINE T operator()(as<T> v) const { return EVE_DISPATCH_CALL(v); }
// Complete the callable interface.
EVE_CALLABLE_OBJECT(some_pi_t, some_pi_);
};
inline constexpr auto some_pi = functor<some_pi_t>;
};
int main()
{
std::cout << eve::some_pi(eve::as(1.0)) << "\n";
std::cout << eve::some_pi(eve::as<eve::wide<float>>{}) << "\n";
std::cout << eve::some_pi[eve::keep_between(1,3)](eve::as<eve::wide<float>>{}) << "\n";
std::cout << eve::some_pi[eve::keep_between(1,3).else_(99)](eve::as<eve::wide<float>>{}) << "\n\n";
std::cout << "Is Pi(as<float>) supported: "
<< std::boolalpha << std::is_invocable_v<eve::tag_t<eve::some_pi>, eve::as<float>>
<< "\n";
std::cout << "Is Pi(float) supported: "
<< std::boolalpha << std::is_invocable_v<eve::tag_t<eve::some_pi>, float>
<< "\n";
std::cout << "Is Pi(as<wide<unsigned char>>) supported: "
<< std::boolalpha << std::is_invocable_v<eve::tag_t<eve::some_pi>, eve::as<eve::wide<unsigned char>>>
<< "\n";
}
The concept value<T> is satisfied if and only if T satisfies either eve::scalar_value or eve::simd_va...
Definition value.hpp:34
#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_DISPATCH_CALL(...)
Generate the proper call to current EVE's Callable Object implementation.
Definition protocol.hpp:148
EVE Main Namespace.
Definition abi.hpp:18
Lightweight type-wrapper.
Definition as.hpp:29
CRTP base class giving an EVE's Callable Object the constant function semantic.
Definition default_behaviors.hpp:313
constexpr auto else_(V const &v) const
Extends a conditional expression with an alternative value.
Definition conditional.hpp:489
Conditional expression keeping all lanes between two position.
Definition conditional.hpp:523
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.