Skip to content

Commit

Permalink
Turned as_value into a new format callable
Browse files Browse the repository at this point in the history
  • Loading branch information
SadiinsoSnowfall committed Feb 4, 2025
1 parent c998c11 commit a329d18
Showing 1 changed file with 44 additions and 43 deletions.
87 changes: 44 additions & 43 deletions include/eve/module/core/constant/as_value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,54 @@

namespace eve
{
//================================================================================================
//! @addtogroup core_conversions
//! @{
//! @var as_value
//! @brief converts eve constant or just a value to a type.
//!
//! **Defined in Header**
//!
//! @code
//! #include <eve/module/core.hpp>
//! @endcode
//!
//! @groupheader{Callable Signatures}
//!
//! @code
//! namespace eve
//! {
//! template< eve::value From, eve::value T >
//! T as_value(From x, eve::as<T> t) noexcept;
//! }
//! @endcode
//!
//! **Parameters**
//!
//! * `x`: either something convertible to T or an of eve constant
//! * `t` : [Type wrapper](@ref eve::as) instance embedding the type of the constant.
//!
//! **Return value**
//!
//! The call `eve::as_value(as<T>())` returns a value of type T which is
//! the conversion of `x` to type Target or the the eve constant of type Target.
//!
//! @groupheader{Example}
//! @godbolt{doc/core/constant/as_value.cpp}
//================================================================================================
EVE_MAKE_CALLABLE(as_value_, as_value);

namespace detail
template<typename Options>
struct as_value_t : constant_callable<as_value_t, Options>
{
template<typename From, value T>
EVE_FORCEINLINE constexpr auto as_value_(EVE_SUPPORTS(cpu_), From from, as<T> const& t) noexcept
EVE_FORCEINLINE constexpr T operator()(From from, as<T> t) const noexcept
{
if constexpr( requires { typename From::constant_callable_tag; } ) return from(t);//if constexpr( instance_of<From,functor> ) return from(t);
else if constexpr( scalar_value<T> ) return static_cast<T>(from);
else return T {from};
if constexpr (requires { typename From::constant_callable_tag; }) return from(t);
else if constexpr (scalar_value<T>) return static_cast<T>(from);
else return T{from};
}
}
};

//================================================================================================
//! @addtogroup core_conversions
//! @{
//! @var as_value
//! @brief converts eve constant or just a value to a type.
//!
//! **Defined in Header**
//!
//! @code
//! #include <eve/module/core.hpp>
//! @endcode
//!
//! @groupheader{Callable Signatures}
//!
//! @code
//! namespace eve
//! {
//! template< eve::value From, eve::value T >
//! T as_value(From x, eve::as<T> t) noexcept;
//! }
//! @endcode
//!
//! **Parameters**
//!
//! * `x`: either something convertible to T or an of eve constant
//! * `t` : [Type wrapper](@ref eve::as) instance embedding the type of the constant.
//!
//! **Return value**
//!
//! The call `eve::as_value(as<T>())` returns a value of type T which is
//! the conversion of `x` to type Target or the the eve constant of type Target.
//!
//! @groupheader{Example}
//! @godbolt{doc/core/constant/as_value.cpp}
//================================================================================================
inline constexpr auto as_value = functor<as_value_t>;
//================================================================================================
//! @}
//================================================================================================
Expand Down

0 comments on commit a329d18

Please sign in to comment.