dune-common 2.10
Loading...
Searching...
No Matches
Dune::CopyableOptional< Type > Class Template Reference

A copyable type wrapper that provides copy/move assignment operations for types that are only copy/move constructible. More...

#include <dune/common/copyableoptional.hh>

Inheritance diagram for Dune::CopyableOptional< Type >:
Inheritance graph

Public Member Functions

template<class T = Type, std::enable_if_t< std::is_default_constructible_v< T >, int > = 0>
constexpr CopyableOptional () noexcept(std::is_nothrow_default_constructible_v< T >)
 Implementation of a default constructor, if the Type is itself default constructible. The internal optional contains a value-initialized Type.
 
template<class T = Type, disableCopyMove< CopyableOptional, T > = 0, std::enable_if_t< std::is_constructible_v< Type, T && >, int > = 0, std::enable_if_t< std::is_convertible_v< T &&, Type >, int > = 0>
constexpr CopyableOptional (T &&value) noexcept(std::is_nothrow_constructible_v< Type, T && >)
 Construct the internal data from perfect forwarding of the passed arguments. Participates in overload resolution if T is implicitly convertible to Type.
 
template<class T = Type, disableCopyMove< CopyableOptional, T > = 0, std::enable_if_t< std::is_constructible_v< Type, T && >, int > = 0, std::enable_if_t< not std::is_convertible_v< T &&, Type >, int > = 0>
constexpr CopyableOptional (T &&value) noexcept(std::is_nothrow_constructible_v< Type, T && >)
 Construct the internal data from perfect forwarding of the passed arguments. Participates in overload resolution if T is not implicitly convertible to Type.
 
template<class... Args, disableCopyMove< CopyableOptional, Args... > = 0, std::enable_if_t<(sizeof...(Args) > 1), int > = 0, std::enable_if_t< std::is_constructible_v< Type, Args &&... >, int > = 0>
constexpr CopyableOptional (Args &&... args) noexcept(std::is_nothrow_constructible_v< Type, Args &&... >)
 Construct the internal data from perfect forwarding of the passed arguments.
 
constexpr CopyableOptional (const CopyableOptional &)=default
 Copy construct the contained value.
 
constexpr CopyableOptional (CopyableOptional &&)=default
 Move construct the contained value.
 
 ~CopyableOptional ()=default
 Default destructor.
 
constexpr CopyableOptionaloperator= (const CopyableOptional &that) noexcept(std::is_nothrow_copy_assignable_v< Type >||(!std::is_copy_assignable_v< Type > &&std::is_nothrow_copy_constructible_v< Type >))
 Copy assignment in terms of copy constructor.
 
template<class T = Type, std::enable_if_t< std::is_move_constructible_v< T >, int > = 0>
constexpr CopyableOptionaloperator= (CopyableOptional &&that) noexcept(std::is_nothrow_move_assignable_v< Type >||(!std::is_move_assignable_v< Type > &&std::is_nothrow_move_constructible_v< Type >))
 Move assignment in terms of move constructor.
 
template<class T = Type, std::enable_if_t< not std::is_same_v< std::decay_t< T >, CopyableOptional >, int > = 0, std::enable_if_t<(std::is_assignable_v< Type &, T >||std::is_constructible_v< Type, T >), int > = 0>
constexpr CopyableOptionaloperator= (T &&value) noexcept(std::is_nothrow_assignable_v< Type &, T >||(!std::is_assignable_v< Type &, T > &&std::is_nothrow_constructible_v< Type, T >))
 Perfect-forwarded assignment or construction.
 

Detailed Description

template<class Type>
class Dune::CopyableOptional< Type >

A copyable type wrapper that provides copy/move assignment operations for types that are only copy/move constructible.

Some types, like lambdas, LocalFiniteElementCache, Geometries,... provide a copy/move constructor but do not provide a corresponding assignment operator. Mostly, the assignment operators can be implemented in terms of the corresponding constructors. This type wrapper provides these assignment operators by internally wrapping the type into a std::optional.

Template Parameters
TypeThe type to be wrapped and equipped with copy operations.

Requirements: Type must be an object type that is copy-constructible

Constructor & Destructor Documentation

◆ CopyableOptional() [1/6]

template<class Type >
template<class T = Type, std::enable_if_t< std::is_default_constructible_v< T >, int > = 0>
Dune::CopyableOptional< Type >::CopyableOptional ( )
inlineconstexprnoexcept

Implementation of a default constructor, if the Type is itself default constructible. The internal optional contains a value-initialized Type.

◆ CopyableOptional() [2/6]

template<class Type >
template<class T = Type, disableCopyMove< CopyableOptional, T > = 0, std::enable_if_t< std::is_constructible_v< Type, T && >, int > = 0, std::enable_if_t< std::is_convertible_v< T &&, Type >, int > = 0>
Dune::CopyableOptional< Type >::CopyableOptional ( T && value)
inlineconstexprnoexcept

Construct the internal data from perfect forwarding of the passed arguments. Participates in overload resolution if T is implicitly convertible to Type.

◆ CopyableOptional() [3/6]

template<class Type >
template<class T = Type, disableCopyMove< CopyableOptional, T > = 0, std::enable_if_t< std::is_constructible_v< Type, T && >, int > = 0, std::enable_if_t< not std::is_convertible_v< T &&, Type >, int > = 0>
Dune::CopyableOptional< Type >::CopyableOptional ( T && value)
inlineexplicitconstexprnoexcept

Construct the internal data from perfect forwarding of the passed arguments. Participates in overload resolution if T is not implicitly convertible to Type.

◆ CopyableOptional() [4/6]

template<class Type >
template<class... Args, disableCopyMove< CopyableOptional, Args... > = 0, std::enable_if_t<(sizeof...(Args) > 1), int > = 0, std::enable_if_t< std::is_constructible_v< Type, Args &&... >, int > = 0>
Dune::CopyableOptional< Type >::CopyableOptional ( Args &&... args)
inlineconstexprnoexcept

Construct the internal data from perfect forwarding of the passed arguments.

◆ CopyableOptional() [5/6]

template<class Type >
Dune::CopyableOptional< Type >::CopyableOptional ( const CopyableOptional< Type > & )
constexprdefault

Copy construct the contained value.

◆ CopyableOptional() [6/6]

template<class Type >
Dune::CopyableOptional< Type >::CopyableOptional ( CopyableOptional< Type > && )
constexprdefault

Move construct the contained value.

◆ ~CopyableOptional()

template<class Type >
Dune::CopyableOptional< Type >::~CopyableOptional ( )
default

Default destructor.

Member Function Documentation

◆ operator=() [1/3]

template<class Type >
CopyableOptional & Dune::CopyableOptional< Type >::operator= ( const CopyableOptional< Type > & that)
inlineconstexprnoexcept

Copy assignment in terms of copy constructor.

◆ operator=() [2/3]

template<class Type >
template<class T = Type, std::enable_if_t< std::is_move_constructible_v< T >, int > = 0>
CopyableOptional & Dune::CopyableOptional< Type >::operator= ( CopyableOptional< Type > && that)
inlineconstexprnoexcept

Move assignment in terms of move constructor.

◆ operator=() [3/3]

template<class Type >
template<class T = Type, std::enable_if_t< not std::is_same_v< std::decay_t< T >, CopyableOptional >, int > = 0, std::enable_if_t<(std::is_assignable_v< Type &, T >||std::is_constructible_v< Type, T >), int > = 0>
CopyableOptional & Dune::CopyableOptional< Type >::operator= ( T && value)
inlineconstexprnoexcept

Perfect-forwarded assignment or construction.


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