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

Helper class to aggregate options handlers and states. More...

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

Detailed Description

template<typename OptionsValues, typename... Options>
struct eve::decorated_with< OptionsValues, Options >

Defined in Header

#include <eve/module/core.hpp>

EVE's Callable Object can be decorated with options. eve::decorated_with is used to list all subset of options a given EVE's Callable Object is allowed to support, how to handle the default values of such subsets and how to store said options states.

Template Parameters
OptionsValuesOptions state type
OptionsList of options specifications to support

Example

Interaction with eve::conditional

#include <iostream>
#include <type_traits>
#include <eve/traits/overload.hpp>
#include <eve/module/core.hpp>
namespace eve
{
// + callable can add rules for decorator to use on a given callable and a default set of options
// + eve::conditional_option give the ability to pass a mask as a decoration.
template<typename Options>
struct func_t : callable<func_t, Options, conditional_option>
{
// Note that decoration doesn't impact signature declaration
template<eve::integral_value T>
EVE_FORCEINLINE T operator()(T v) const { return EVE_DISPATCH_CALL(v); }
EVE_CALLABLE_OBJECT(func_t, func_);
};
// Build the callable object from the function object type
inline constexpr auto func = functor<func_t>;
template<typename Options>
struct other_func_t : callable<other_func_t, Options, relative_conditional_option>
{
// Note that decoration doesn't impact signature declaration
template<eve::integral_value T>
EVE_FORCEINLINE T operator()(T v) const { return EVE_DISPATCH_CALL(v); }
EVE_CALLABLE_OBJECT(other_func_t, other_func_);
};
// Build the callable object from the function object type
inline constexpr auto other_func = functor<other_func_t>;
};
namespace eve::detail
{
// Decorated callable takes a eve::options as first parameter
auto func_(EVE_REQUIRES(cpu_), eve::callable_options auto const& opts, eve::integral_value auto x)
{
// See RABERU documentation to check and access options inside a decorator.
auto const mask = opts[condition_key];
if constexpr(decltype(mask)::is_complete) return x*x;
else return eve::mul[mask](10,x);
}
auto other_func_(EVE_REQUIRES(cpu_), eve::callable_options auto const& opts, eve::integral_value auto x)
{
// See RABERU documentation to check and access options inside a decorator.
auto const mask = opts[condition_key];
if constexpr(decltype(mask)::is_complete) return x/10;
else return eve::mul[mask](x,x);
}
}
template<typename Func, typename Opt>
inline constexpr bool can_be_decorated_with = requires(Func f, Opt o) { f[o]; };
int main()
{
std::cout << eve::func(8) << "\n";
std::cout << eve::func[false](8) << "\n";
std::cout << eve::func(eve::wide<short>{77}) << "\n";
std::cout << eve::func[eve::keep_between(2,6)](eve::wide<short>{77}) << "\n";
std::cout << eve::other_func(80) << "\n";
std::cout << eve::other_func(eve::wide<short>{77}) << "\n";
std::cout << eve::other_func[eve::keep_between(2,6)](eve::wide<short>{77}) << "\n";
std::cout << "Is func[bool] supported: "
<< std::boolalpha << can_be_decorated_with<eve::tag_t<eve::func>, bool>
<< "\n";
std::cout << "Is func[eve::keep_between] supported: "
<< std::boolalpha << can_be_decorated_with<eve::tag_t<eve::func>, eve::keep_between>
<< "\n";
std::cout << "Is other_func[bool] supported: "
<< std::boolalpha << can_be_decorated_with<eve::tag_t<eve::other_func>, bool>
<< "\n";
std::cout << "Is other_func[eve::keep_between] supported: "
<< std::boolalpha << can_be_decorated_with<eve::tag_t<eve::other_func>, eve::keep_between>
<< "\n";
}
The concept integral_value<T> is satisfied if and only if T satisfies eve::value and the element type...
Definition value.hpp:51
constexpr auto mul
tuple_callablecomputing the product of its arguments. ! ! @groupheader{Header file}...
Definition mul.hpp:119
#define EVE_CALLABLE_OBJECT(TYPE, NAME)
Generate the generic function interface for an actual eve::callable.
Definition protocol.hpp:131
constexpr detail::condition_key_t condition_key
Keyword for retrieving conditionals decorator.
Definition supports.hpp:195
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
Conditional expression keeping all lanes between two position.
Definition conditional.hpp:523
Wrapper for SIMD registers.
Definition wide.hpp:70

Interaction with custom specifications

#include <iostream>
#include <type_traits>
#include <eve/traits/overload.hpp>
#include <eve/wide.hpp>
namespace eve
{
// Defines two RABERU flags
using namespace rbr::literals;
inline constexpr auto precise = "precise"_fl;
inline constexpr auto scale = "scale"_fl;
// Defines a support specification
struct precision
{
template<eve::any_options_from<precise, scale> O>
auto process(auto const& base, O const& opt) const
{
auto new_opts = rbr::merge(options{opt}, base);
return options<decltype(new_opts)>{new_opts};
}
constexpr auto default_to(auto const& base) const noexcept { return base; }
};
// Make this callable supports the precision options
template<typename Options>
struct func_t : callable<func_t, Options, precision>
{
double operator()(int v) const { return EVE_DISPATCH_CALL(v); }
EVE_CALLABLE_OBJECT(func_t, func_);
};
// Build the callable object from the function object type
inline constexpr auto func = functor<func_t>;
};
namespace eve::detail
{
auto func_(EVE_REQUIRES(cpu_), eve::callable_options auto const& opt, int x)
{
// We retrieve the option's value via the RABERU settings interface
return x * (opt[scale] ? 10. : 1.)
+ (opt[precise] ? 3.1416 : 3.2);
}
}
int main()
{
std::cout << eve::func(1) << "\n";
std::cout << eve::func[eve::precise](1) << "\n";
std::cout << eve::func[eve::scale](1) << "\n";
std::cout << eve::func[eve::scale][eve::precise](1) << "\n";
std::cout << eve::func[eve::precise][eve::scale](1) << "\n";
}
Wrapper class around bundle of options passed to eve::callable.
Definition supports.hpp:37

Public Member Functions

template<typename O >
requires ( requires(OptionsValues const& ov) { this->process(ov,o);} )
constexpr auto operator[] (O o) const
 Adds an option to current callable.
 
constexpr auto options () const
 Retrieves the current options' state, including processed default.