SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
seqan3::detail::deferred_crtp_base< crtp_base, args_t > Struct Template Reference

An invocable wrapper that defers the instantiation of a crtp_base class. More...

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

Public Types

template<typename derived_t >
using invoke = crtp_base< derived_t, args_t... >
 Invokes the deferred crtp_base with the corresponding derived type.
 

Detailed Description

template<template< typename... > typename crtp_base, typename... args_t>
struct seqan3::detail::deferred_crtp_base< crtp_base, args_t >

An invocable wrapper that defers the instantiation of a crtp_base class.

Template Parameters
crtp_baseThe crtp base class to be deferred. Must be a template template parameter.
args_tA type template parameter pack used to augment the crtp_base class.

This transformation trait wrapper allows to defer the template instantiation of crtp-base classes. This can be useful if the crtp_base class should be augmented with traits or other templates, especially when using variadic crtp_bases. The help function seqan3::detail::invoke_deferred_crtp_base can be used to instantiate the deferred crtp base with the respective derived type.

Example

The following snippet demonstrates the use of the deferred crtp base class instantiation.

// 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
#include <string>
#include <type_traits>
// Defines a crtp_base class with an additional value type.
template <typename derived_t, int value>
class base1
{
public:
int func1() const
{
return value;
}
};
// Defines a crtp_base class with an additional value type and a parameter type.
template <typename derived_t, typename value_t, typename parameter_t>
class base2
{
public:
value_t func2(parameter_t const p) const
{
return static_cast<value_t>(p);
}
};
// The derived class that inherits from a variadic crtp pattern, which are augmented with additional trait types.
// These types must be wrapped in a deferred layer, otherwise the compilation fails as incomplete types are not allowed.
// But during the definition of the base classes, the derived class cannot be known.
// In addition the deferred type must be invoked with the derived class using the `invoke_deferred_crtp_base` helper
// template to instantiate the correct crtp base type.
// Note that it is possible to define base classes with type template parameters (see base2) or
// non-type template parameters (see base1), but non-type and type template parameters cannot be mixed in one
// base class definition.
template <typename... deferred_bases_t>
class derived : public seqan3::detail::invoke_deferred_crtp_base<deferred_bases_t, derived<deferred_bases_t...>>...
{};
int main()
{
// Define deferred base with non-type template parameter
// Define deferred base with type template parameter.
// Instantiate the derived class with the deferred crtp base classes.
derived<deferred_base1, deferred_base2> d{};
// Check the inherited interfaces.
static_assert(std::is_same_v<decltype(d.func1()), int>, "Return type must be int");
static_assert(std::is_same_v<decltype(d.func2(10u)), uint8_t>, "Return type must be uint8_t");
}
Provides seqan3::detail::deferred_crtp_base.
typename deferred_crtp_base_t::template invoke< derived_t > invoke_deferred_crtp_base
Template alias to instantiate the deferred crtp base with the derived class.
Definition deferred_crtp_base.hpp:94
T is_same_v
An invocable wrapper that defers the instantiation of a crtp_base class.
Definition deferred_crtp_base.hpp:73
An invocable wrapper that defers the instantiation of a crtp_base class.
Definition deferred_crtp_base.hpp:40
See also
seqan3::detail::invoke_deferred_crtp_base
seqan3::detail::deferred_crtp_base_vargs

Member Typedef Documentation

◆ invoke

template<template< typename... > typename crtp_base, typename... args_t>
template<typename derived_t >
using seqan3::detail::deferred_crtp_base< crtp_base, args_t >::invoke = crtp_base<derived_t, args_t...>

Invokes the deferred crtp_base with the corresponding derived type.

Template Parameters
derived_tThe derived type to instantiate the crtp_base with.

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