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>

Public Member Functions

constexpr copyable_wrapper ()=default
 copyable_wrapper is default constructible, iff the wrapped type is default initialisable.
 
constexpr copyable_wrapper (copyable_wrapper &&)=default
 Defaulted.
 
constexpr copyable_wrapper (copyable_wrapper const &)=default
 Defaulted.
 
template<typename... args_t>
requires std::constructible_from<t, args_t...>
constexpr copyable_wrapper (std::in_place_t, args_t... args) noexcept(std::is_nothrow_constructible_v< t, args_t... >)
 Construct from argument pack. Part of the std::optional API.
 
constexpr copyable_wrapper (t &&other) noexcept(std::is_nothrow_move_constructible_v< t >)
 Move construct from value.
 
constexpr copyable_wrapper (t const &other) noexcept(std::is_nothrow_copy_constructible_v< t >)
 Copy construct from value.
 
constexpr bool has_value () const noexcept
 Return whether the wrapper contains a value. Part of the std::optional API.
 
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 t const & operator* () const noexcept
 Returns a reference to the wrapped object. Part of the std::optional API.
 
constexpr t & operator* () noexcept
 Returns a reference to the wrapped object. Part of the std::optional API.
 
constexpr t const * operator-> () const noexcept
 Returns a pointer to the wrapped object. Part of the std::optional API.
 
constexpr t * operator-> () noexcept
 Returns a pointer to the wrapped object. Part of the std::optional API.
 
constexpr copyable_wrapperoperator= (copyable_wrapper &&)=default
 Move assignment for copyable types is the default move assignment.
 
constexpr copyable_wrapperoperator= (copyable_wrapper &&other) noexcept
 Move assignment for non-copyable types uses the Destroy-then-copy paradigm.
 
constexpr copyable_wrapperoperator= (copyable_wrapper const &)=default
 Copy assignment for copyable types is the default copy assignment.
 
constexpr copyable_wrapperoperator= (copyable_wrapper const &other) noexcept
 Copy assignment for non-copyable types uses the Destroy-then-copy paradigm.
 
constexpr ~copyable_wrapper ()=default
 Defaulted.
 

Private Attributes

value {}
 An object of the wrapped type.
 

Detailed Description

template<boxable t>
requires std::copyable<t> || (std::is_nothrow_move_constructible_v<t> && std::is_nothrow_copy_constructible_v<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

If t is std::copyable, the STL allows to store t directly, i.e. no std::optional is needed.

Member Function Documentation

◆ operator()()

template<boxable 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.

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