SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
seqan3::detail::copyable_wrapper< t > Class Template Reference

Utility wrapper that behaves like std::optional but makes the type conform with the std::copyable concept. More...

#include <seqan3/core/detail/copyable_wrapper.hpp>

+ Inheritance diagram for seqan3::detail::copyable_wrapper< t >:

Public Member Functions

constexpr copyable_wrapper () noexcept(std::is_nothrow_default_constructible_v< t >)
 Use a specialised default constructor, if the wrapped type is default initialisable. If not, the default constructor of std::optional is used.
 
constexpr copyable_wrapper (copyable_wrapper &&)=default
 Defaulted.
 
constexpr copyable_wrapper (copyable_wrapper const &)=default
 < Use std::optional assignment operators.
 
template<typename... args_t>
requires std::invocable<t, args_t...>
constexpr decltype(auto) operator() (args_t... args) const noexcept(std::is_nothrow_invocable_v< t, args_t... >)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename... args_t>
requires std::invocable<t, args_t...>
constexpr decltype(auto) operator() (args_t... args) noexcept(std::is_nothrow_invocable_v< t, args_t... >)
 Invokes the wrapped object with passed arguments.
 
constexpr copyable_wrapperoperator= (copyable_wrapper &&other) noexcept(std::is_nothrow_move_constructible_v< t >)
 Move assignment for non-movable wrapped types.
 
constexpr copyable_wrapperoperator= (copyable_wrapper const &other) noexcept(std::is_nothrow_copy_constructible_v< t >)
 Copy assignment for non-copyable wrapped types.
 
constexpr ~copyable_wrapper ()=default
 Defaulted.
 
- Public Member Functions inherited from std::optional< t >
emplace (T... args)
 
has_value (T... args)
 
operator bool (T... args)
 
operator* (T... args)
 
operator-> (T... args)
 
operator= (T... args)
 
optional (T... args)
 
reset (T... args)
 
swap (T... args)
 
value (T... args)
 
value_or (T... args)
 
~optional (T... args)
 

Related Symbols

(Note that these are not member symbols.)

template<typename t >
 copyable_wrapper (t) -> copyable_wrapper< std::remove_reference_t< t > >
 Type deduction guide that strips references.
 

Detailed Description

template<typename t>
class seqan3::detail::copyable_wrapper< t >

Utility wrapper that behaves like std::optional but makes the type conform with the std::copyable concept.

See also
https://en.cppreference.com/w/cpp/ranges/copyable_wrapper

Constructor & Destructor Documentation

◆ copyable_wrapper()

template<typename t >
constexpr seqan3::detail::copyable_wrapper< t >::copyable_wrapper ( copyable_wrapper< t > const &  )
constexprdefault

< Use std::optional assignment operators.

Defaulted.

Member Function Documentation

◆ operator()()

template<typename t >
template<typename... args_t>
requires std::invocable<t, args_t...>
constexpr decltype(auto) seqan3::detail::copyable_wrapper< t >::operator() ( args_t...  args)
inlineconstexprnoexcept

Invokes the wrapped object with passed arguments.

Exceptions
std::bad_optional_accessif no value is contained.

This is a SeqAn-specific extension that allows easy invocation of the wrapped object. t needs to be callable with the passed arguments.

Constness of this function depends on the constness of the call-operator of the wrapped object.

// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
int main()
{
int outer{};
// Might be used for non-copyable lambdas. In this example, the lambda would be copyable even without the wrapper.
seqan3::detail::copyable_wrapper wrapper{[&outer](int const x)
{
outer += x;
return outer;
}};
auto wrapper_2 = wrapper; // Would not work with non-copyable lambda.
seqan3::debug_stream << wrapper(2) << '\n'; // 2
seqan3::debug_stream << wrapper_2(4) << '\n'; // 6
}
Utility wrapper that behaves like std::optional but makes the type conform with the std::copyable con...
Definition copyable_wrapper.hpp:34
Provides seqan3::detail::copyable_wrapper.
Provides seqan3::debug_stream and related types.
debug_stream_type debug_stream
A global instance of seqan3::debug_stream_type.
Definition debug_stream.hpp:37

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