OGLplus  (0.59.0) a C++ wrapper for rendering APIs

eagine::valid_if< T, Policy, DoLog > Class Template Reference

Primary template for conditionally valid values. More...

#include <eagine/valid_if/decl.hpp>

Public Member Functions

auto operator= (const T &v) -> auto &
 Copies argument into this instance.
 
auto operator= (T &&v) -> auto &
 Moves argument into this instance.
 
 operator bool () const noexcept
 Indicates if the stored value is valid according to policy. More...
 
template<typename Func >
auto then (const Func &func) const -> std::enable_if_t< !std::is_same_v< std::result_of_t< Func(T)>, void >, valid_if< std::result_of_t< Func(T)>, valid_flag_policy >>
 Calls the specified function if the stored valus is valid. More...
 
template<typename Func >
auto operator| (const Func &func) const
 Calls the specified function if the stored valus is valid. More...
 
auto operator/ (const T &fallback) const noexcept -> const T &
 Returns the stored value if valid, returns fallback otherwise. More...
 
auto operator* () const noexcept -> const T &
 Returns the stored value, throws if it is invalid. More...
 
auto operator-> () const noexcept -> const T *
 Returns pointer to the stored value, throws if it is invalid. More...
 
constexpr auto operator== (const T &v) const -> tribool
 Equality comparison of the stored value with v.
 
constexpr auto operator!= (const T &v) const -> tribool
 Non-equality comparison of the stored value with v.
 
constexpr auto operator< (const T &v) const -> tribool
 Less-than comparison of the stored value with v.
 
constexpr auto operator> (const T &v) const -> tribool
 Greater-than comparison of the stored value with v.
 
constexpr auto operator<= (const T &v) const -> tribool
 Less-equal comparison of the stored value with v.
 
constexpr auto operator>= (const T &v) const -> tribool
 Greater-equal comparison of the stored value with v.
 
constexpr auto is_valid (const T &val, P... p) const noexcept -> bool
 Checks if val is valid according to this object's policy. More...
 
constexpr auto is_valid (P... p) const noexcept
 Checks if the stored value is valid according to policy. More...
 
auto value (P... p) -> T &
 Returns the stored value if it is valid otherwise throws. More...
 
auto value (P... p) const -> const T &
 Returns the stored value if it is valid, otherwise throws. More...
 
auto value_or (T &fallback, P... p) noexcept -> auto &
 Returns the stored value if valid, otherwise returns fallback. More...
 
constexpr auto value_or (const T &fallback, P... p) const noexcept -> auto &
 Returns the stored value if valid, otherwise returns fallback. More...
 
- Public Member Functions inherited from eagine::basic_valid_if< T, Policy, typename Policy::do_log >
constexpr basic_valid_if () noexcept
 Default constructor.
 
constexpr basic_valid_if (T val) noexcept
 Constructor initializing the stored value by val.
 
constexpr basic_valid_if (T val, Policy plcy) noexcept
 Constructor initializing the stored value and policy.
 
constexpr basic_valid_if (const basic_valid_if &that)
 Copy constructor.
 
 basic_valid_if (basic_valid_if &&that) noexcept(std::is_nothrow_move_constructible_v< T >)
 Move constructor.
 
auto policy () const noexcept -> const Policy &
 Returns a reference to this object's policy.
 
auto operator= (const basic_valid_if &that) -> auto &
 Copy assignment operator.
 
auto operator= (basic_valid_if &&that) noexcept(std::is_nothrow_move_assignable_v< T >) -> auto &
 Move assignment operator.
 
auto operator= (const T &value) -> auto &
 Copies value into this instance.
 
 ~basic_valid_if () noexcept=default
 The destructor.
 
constexpr auto is_valid (const T &val, P... p) const noexcept -> bool
 Checks if val is valid according to this object's policy. More...
 
constexpr auto is_valid (P... p) const noexcept
 Checks if the stored value is valid according to policy. More...
 
constexpr auto has_value (P... p) const noexcept
 Checks if the stored value is valid according to policy. More...
 
auto call_if_invalid (Func func, P... p) -> auto &
 Calls the specified function if the stored value is invalid. More...
 
void throw_if_invalid (P... p) const
 Throws an exception if the stored value is invalid. More...
 
auto value (P... p) -> T &
 Returns the stored value if it is valid otherwise throws. More...
 
auto value (P... p) const -> const T &
 Returns the stored value if it is valid, otherwise throws. More...
 
auto value_or (T &fallback, P... p) noexcept -> auto &
 Returns the stored value if valid, otherwise returns fallback. More...
 
constexpr auto value_or (const T &fallback, P... p) const noexcept -> auto &
 Returns the stored value if valid, otherwise returns fallback. More...
 
constexpr auto value_anyway (P...) const noexcept -> auto &
 Returns the stored value regardless of its validity.
 
constexpr auto value_anyway (P...) noexcept -> auto &
 Returns the stored value regardless of its validity.
 
auto then (const Func &func, P... p) const -> std::enable_if_t< std::is_same_v< std::result_of_t< Func(T)>, void >>
 Calls the specified function if the stored value is valid. More...
 
constexpr auto transformed (Func func, P... p) const noexcept
 Calls a binary transforming function on {value, is_valid()} pair. More...
 
- Public Member Functions inherited from eagine::basic_valid_if_value< T >
constexpr basic_valid_if_value (T value) noexcept(noexcept(T(std::declval< T && >())))
 Initializing constructor.
 
constexpr basic_valid_if_value () noexcept(std::is_nothrow_default_constructible_v< T >)=default
 Default constructor.
 
constexpr basic_valid_if_value (basic_valid_if_value &&) noexcept(std::is_nothrow_move_constructible_v< T >)=default
 Move constructor.
 
constexpr basic_valid_if_value (const basic_valid_if_value &) noexcept(std::is_nothrow_copy_constructible_v< T >)=default
 Copy constructor.
 
auto operator= (basic_valid_if_value &&) noexcept(std::is_nothrow_move_assignable_v< T >) -> basic_valid_if_value &=default
 Move assignment operator.
 
auto operator= (const basic_valid_if_value &) noexcept(std::is_nothrow_copy_assignable_v< T >) -> basic_valid_if_value &=default
 Copy assignment operator.
 
 ~basic_valid_if_value () noexcept=default
 The destructor.
 
auto operator= (const T &v) -> auto &
 Copies v to the stored value.
 
auto operator= (T &&v) -> auto &
 Moves v to the stored value.
 

Detailed Description

template<typename T, typename Policy, typename DoLog = typename Policy::do_log>
class eagine::valid_if< T, Policy, DoLog >

Primary template for conditionally valid values.

Examples
eagine/bindump.cpp, and eagine/c_api_wrap.cpp.

Member Function Documentation

◆ is_valid() [1/2]

template<typename T , typename Policy , typename DoLog = typename Policy::do_log>
constexpr auto eagine::basic_valid_if< T, Policy, DoLog, P >::is_valid
inlineconstexprnoexcept

Checks if val is valid according to this object's policy.

Parameters
padditional parameters for the policy validity check function.

◆ is_valid() [2/2]

template<typename T , typename Policy , typename DoLog = typename Policy::do_log>
constexpr auto eagine::basic_valid_if< T, Policy, DoLog, P >::is_valid
inlineconstexprnoexcept

Checks if the stored value is valid according to policy.

Parameters
padditional parameters for the policy validity check function.

◆ operator bool()

template<typename T , typename Policy , typename DoLog = typename Policy::do_log>
eagine::valid_if< T, Policy, DoLog >::operator bool ( ) const
inlineexplicitnoexcept

Indicates if the stored value is valid according to policy.

See also
basic_valid_if::is_valid

◆ operator*()

template<typename T , typename Policy , typename DoLog = typename Policy::do_log>
auto eagine::valid_if< T, Policy, DoLog >::operator* ( ) const -> const T&
inlinenoexcept

Returns the stored value, throws if it is invalid.

See also
basic_valid_if::value
Exceptions
std::runtime_error

◆ operator->()

template<typename T , typename Policy , typename DoLog = typename Policy::do_log>
auto eagine::valid_if< T, Policy, DoLog >::operator-> ( ) const -> const T*
inlinenoexcept

Returns pointer to the stored value, throws if it is invalid.

See also
basic_valid_if::value
Exceptions
std::runtime_error

◆ operator/()

template<typename T , typename Policy , typename DoLog = typename Policy::do_log>
auto eagine::valid_if< T, Policy, DoLog >::operator/ ( const T &  fallback) const -> const T&
inlinenoexcept

Returns the stored value if valid, returns fallback otherwise.

See also
basic_valid_if::value_or

◆ operator|()

template<typename T , typename Policy , typename DoLog = typename Policy::do_log>
template<typename Func >
auto eagine::valid_if< T, Policy, DoLog >::operator| ( const Func &  func) const
inline

Calls the specified function if the stored valus is valid.

Parameters
functhe function to call.
See also
then

◆ then()

template<typename T , typename Policy , typename DoLog = typename Policy::do_log>
template<typename Func >
auto eagine::valid_if< T, Policy, DoLog >::then ( const Func &  func) const -> std::enable_if_t< !std::is_same_v<std::result_of_t<Func(T)>, void>, valid_if<std::result_of_t<Func(T)>, valid_flag_policy>>
inline

Calls the specified function if the stored valus is valid.

Parameters
functhe function to call.

Referenced by eagine::valid_if< std::chrono::seconds >::operator|().

◆ value() [1/2]

template<typename T , typename Policy , typename DoLog = typename Policy::do_log>
auto eagine::basic_valid_if< T, Policy, DoLog, P >::value
inline

Returns the stored value if it is valid otherwise throws.

Parameters
padditional parameters for the policy validity check function.
Exceptions
std::runtime_error

◆ value() [2/2]

template<typename T , typename Policy , typename DoLog = typename Policy::do_log>
auto eagine::basic_valid_if< T, Policy, DoLog, P >::value
inline

Returns the stored value if it is valid, otherwise throws.

Parameters
padditional parameters for the policy validity check function.
Exceptions
std::runtime_error

◆ value_or() [1/2]

template<typename T , typename Policy , typename DoLog = typename Policy::do_log>
constexpr auto eagine::basic_valid_if< T, Policy, DoLog, P >::value_or
inlineconstexprnoexcept

Returns the stored value if valid, otherwise returns fallback.

Parameters
padditional parameters for the policy validity check function.

◆ value_or() [2/2]

template<typename T , typename Policy , typename DoLog = typename Policy::do_log>
auto eagine::basic_valid_if< T, Policy, DoLog, P >::value_or
inlinenoexcept

Returns the stored value if valid, otherwise returns fallback.

Parameters
padditional parameters for the policy validity check function.

The documentation for this class was generated from the following file:

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).