E.V.E
v2023.02.15
 
Loading...
Searching...
No Matches
eve::conditional_option Struct Reference

Option specification for decoration via conditional value and expressions. More...

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

Detailed Description

Defined in Header

#include <eve/module/core.hpp>

eve::conditional_option is an option specification that can be used when defining a eve::callable type to make it supports decoration via bool, eve::logical, any eve::conditional_expr or eve::relative_conditional_expr.

Example

#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:86

Public Member Functions

constexpr auto default_to (auto const &base) const
 Default settings of eve::conditional is eve::ignore_none.