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

eagine::basic_valid_if< T, Policy, DoLog, P > Class Template Reference

Basic template for conditionally-valid values. More...

#include <eagine/valid_if/base.hpp>

Public Member Functions

auto policy () const noexcept -> const Policy &
 Returns a reference to this object's policy.
 
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 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...
 
template<typename Func >
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.
 
template<typename Func >
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...
 
template<typename Func >
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.
 

Friends

constexpr friend auto operator== (const basic_valid_if &a, const basic_valid_if &b) noexcept -> bool
 Equality comparison.
 

Detailed Description

template<typename T, typename Policy, typename DoLog, typename... P>
class eagine::basic_valid_if< T, Policy, DoLog, P >

Basic template for conditionally-valid values.

Template Parameters
Ttype of the stored, conditionally valid value.
Policyindicates under what conditions is the stored value valid.

Member Function Documentation

◆ call_if_invalid()

template<typename T , typename Policy , typename DoLog , typename... P>
template<typename Func >
auto eagine::basic_valid_if< T, Policy, DoLog, P >::call_if_invalid ( Func  func,
P...  p 
) -> auto&
inline

Calls the specified function if the stored value is invalid.

Parameters
functhe function to be called.
padditional parameters for the policy validity check function.

◆ has_value()

template<typename T , typename Policy , typename DoLog , typename... P>
constexpr auto eagine::basic_valid_if< T, Policy, DoLog, P >::has_value ( P...  p) const
inlineconstexprnoexcept

Checks if the stored value is valid according to policy.

Parameters
padditional parameters for the policy validity check function.

◆ is_valid() [1/2]

template<typename T , typename Policy , typename DoLog , typename... P>
constexpr auto eagine::basic_valid_if< T, Policy, DoLog, P >::is_valid ( const T &  val,
P...  p 
) const -> bool
inlineconstexprnoexcept

◆ is_valid() [2/2]

template<typename T , typename Policy , typename DoLog , typename... P>
constexpr auto eagine::basic_valid_if< T, Policy, DoLog, P >::is_valid ( P...  p) const
inlineconstexprnoexcept

Checks if the stored value is valid according to policy.

Parameters
padditional parameters for the policy validity check function.

◆ then()

template<typename T , typename Policy , typename DoLog , typename... P>
template<typename Func >
auto eagine::basic_valid_if< T, Policy, DoLog, P >::then ( const Func &  func,
P...  p 
) const -> std::enable_if_t<std::is_same_v<std::result_of_t<Func(T)>, void>>
inline

Calls the specified function if the stored value is valid.

Parameters
functhe function to be called.
padditional parameters for the policy validity check function.

◆ throw_if_invalid()

template<typename T , typename Policy , typename DoLog , typename... P>
void eagine::basic_valid_if< T, Policy, DoLog, P >::throw_if_invalid ( P...  p) const
inline

Throws an exception if the stored value is invalid.

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

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

◆ transformed()

template<typename T , typename Policy , typename DoLog , typename... P>
template<typename Func >
constexpr auto eagine::basic_valid_if< T, Policy, DoLog, P >::transformed ( Func  func,
P...  p 
) const
inlineconstexprnoexcept

Calls a binary transforming function on {value, is_valid()} pair.

Parameters
functhe function to be called.
padditional parameters for the policy validity check function.

◆ value() [1/2]

template<typename T , typename Policy , typename DoLog , typename... P>
auto eagine::basic_valid_if< T, Policy, DoLog, P >::value ( P...  p) -> T&
inline

Returns the stored value if it is valid otherwise throws.

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

Referenced by eagine::basic_valid_if< T, P, typename P ::do_log >::operator=().

◆ value() [2/2]

template<typename T , typename Policy , typename DoLog , typename... P>
auto eagine::basic_valid_if< T, Policy, DoLog, P >::value ( P...  p) const -> const T&
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... P>
constexpr auto eagine::basic_valid_if< T, Policy, DoLog, P >::value_or ( const T &  fallback,
P...  p 
) const -> auto&
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... P>
auto eagine::basic_valid_if< T, Policy, DoLog, P >::value_or ( T &  fallback,
P...  p 
) -> auto&
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).