SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
Type Pack

Provides metaprogramming utilities for working on template parameter packs. More...

+ Collaboration diagram for Type Pack:

Functions

template<typename unary_predicate_t , typename... pack_t>
requires (std::predicate<unary_predicate_t, pack_t> && ...)
constexpr bool seqan3::detail::all_of (unary_predicate_t &&fn, pack_t &&... args)
 Tests whether a given predicate evaluates to true for each element in the function parameter pack.
 
template<ptrdiff_t idx, typename head_t , typename... tail_t>
auto seqan3::pack_traits::detail::at ()
 Implementation for seqan3::pack_traits::at.
 
template<typename head_t , typename... tail_t>
type_list< tail_t... > seqan3::pack_traits::detail::drop_front ()
 Implementation for seqan3::pack_traits::drop_front.
 
template<typename query_t , typename... pack_t>
constexpr ptrdiff_t seqan3::pack_traits::detail::find ()
 Implementation for seqan3::pack_traits::find.
 
template<template< typename > typename pred_t, typename... pack_t>
constexpr ptrdiff_t seqan3::pack_traits::detail::find_if ()
 Implementation for seqan3::pack_traits::find_if.
 
template<typename unary_function_t , typename... pack_t>
requires (std::invocable<unary_function_t, pack_t> && ...)
constexpr void seqan3::detail::for_each (unary_function_t &&fn, pack_t &&... args)
 Applies a function to each element of the given function parameter pack.
 
template<typename head_t , typename... tail_t>
std::type_identity< head_t > seqan3::pack_traits::detail::front ()
 Implementation for seqan3::pack_traits::front.
 
template<typename replace_t , ptrdiff_t idx, typename... pack_t, size_t... i>
auto seqan3::pack_traits::detail::replace_at (std::index_sequence< i... >) -> type_list< std::conditional_t< i==idx, replace_t, pack_t >... >
 Implementation for seqan3::pack_traits::replace_at.
 
template<ptrdiff_t idx, typename head_t , typename... pack2_t, typename... pack1_t>
auto seqan3::pack_traits::detail::split_after (type_list< pack1_t... >)
 Implementation for seqan3::pack_traits::split_after.
 

Type pack traits (return a single type)

template<ptrdiff_t idx, typename... pack_t>
using seqan3::pack_traits::at = typename decltype(detail::at< idx, pack_t... >())::type
 Return the type at given index from the type pack.
 
template<typename... pack_t>
using seqan3::pack_traits::front = typename decltype(detail::front< pack_t... >())::type
 Return the first type from the type pack.
 
template<typename... pack_t>
using seqan3::pack_traits::back = typename decltype((std::type_identity< pack_t >{},...))::type
 Return the last type from the type pack.
 

Type pack traits (return a type list)

template<typename... pack_t>
using seqan3::pack_traits::drop_front = typename decltype(detail::drop_front< pack_t... >())::type
 Return a seqan3::type_list of all the types in the type pack, except the first.
 
template<template< typename > typename trait_t, typename... pack_t>
using seqan3::pack_traits::transform = seqan3::type_list< trait_t< pack_t >... >
 Apply a transformation trait to every type in the pack and return a seqan3::type_list of the results.
 
template<ptrdiff_t i, typename... pack_t>
using seqan3::pack_traits::take = typename decltype(detail::split_after< i, pack_t... >(type_list<>{}))::first_type
 Return a seqan3::type_list of the first n types in the type pack.
 
template<ptrdiff_t i, typename... pack_t>
using seqan3::pack_traits::drop = typename decltype(detail::split_after< i, pack_t... >(type_list<>{}))::second_type
 Return a seqan3::type_list of the types in the type pack, except the first n.
 
template<ptrdiff_t i, typename... pack_t>
using seqan3::pack_traits::take_last = drop< size< pack_t... > - i, pack_t... >
 Return a seqan3::type_list of the last n types in the type pack.
 
template<ptrdiff_t i, typename... pack_t>
using seqan3::pack_traits::drop_last = take< size< pack_t... > - i, pack_t... >
 Return a seqan3::type_list of the types the type pack, except the last n.
 
template<ptrdiff_t i, typename... pack_t>
using seqan3::pack_traits::split_after = decltype(detail::split_after< i, pack_t... >(type_list<>{}))
 Split a type pack into two parts returned as a pair of seqan3::type_list.
 
template<typename replace_t , std::ptrdiff_t i, typename... pack_t>
using seqan3::pack_traits::replace_at = decltype(detail::replace_at< replace_t, i, pack_t... >(std::make_index_sequence< size< pack_t... > >{}))
 Replace the type at the given index with the given type.
 

Type pack traits (return a value)

template<typename... pack_t>
constexpr size_t seqan3::pack_traits::size = sizeof...(pack_t)
 The size of a type pack.
 
template<typename query_t , typename... pack_t>
constexpr ptrdiff_t seqan3::pack_traits::count = (std::is_same_v<query_t, pack_t> + ... + 0)
 Count the occurrences of a type in a pack.
 
template<typename query_t , typename... pack_t>
constexpr ptrdiff_t seqan3::pack_traits::find = seqan3::pack_traits::detail::find<query_t, pack_t...>()
 Get the index of the first occurrence of a type in a pack.
 
template<template< typename > typename pred_t, typename... pack_t>
constexpr ptrdiff_t seqan3::pack_traits::find_if = seqan3::pack_traits::detail::find_if<pred_t, pack_t...>()
 Get the index of the first type in a pack that satisfies the given predicate.
 
template<typename query_t , typename... pack_t>
constexpr bool seqan3::pack_traits::contains = (find<query_t, pack_t...> != -1)
 Whether a type occurs in a pack or not.
 

Detailed Description

Provides metaprogramming utilities for working on template parameter packs.

See also
Utility

This module contains auxiliary functions, algorithms and traits on template parameter packs. All traits on a template parameter pack are defined in the header <seqan3/utility/type_pack/traits.hpp>.

Typedef Documentation

◆ at

template<ptrdiff_t idx, typename... pack_t>
using seqan3::pack_traits::at = typedef typename decltype(detail::at<idx, pack_t...>())::type

Return the type at given index from the type pack.

Template Parameters
idxThe index; must be smaller than the size of the pack.
pack_tThe type pack.

Negative indexes are supported (e.g. at<-1, int, double, bool &> is bool &).

(Compile-time) Complexity

  • Number of template instantiations: O(n)
  • Other operations: O(n)
// 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()
{
// Look at the 2nd element.
static_assert(std::same_as<float, seqan3::pack_traits::at<1, int, float, bool, double>>);
// Look at the last element.
static_assert(std::same_as<double, seqan3::pack_traits::at<-1, int, float, bool, double>>);
}
typename decltype(detail::at< idx, pack_t... >())::type at
Return the type at given index from the type pack.
Definition type_pack/traits.hpp:245
Provides various traits for template packs.

◆ back

template<typename... pack_t>
using seqan3::pack_traits::back = typedef typename decltype((std::type_identity<pack_t>{}, ...))::type

Return the last type from the type pack.

Template Parameters
pack_tThe type pack.

(Compile-time) Complexity

  • Number of template instantiations: O(n) (possibly O(1))
  • Other operations: O(1)

Notably faster than seqan3::pack_traits::at<size<pack...> - 1, pack...> (no recursive template instantiations).

// 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()
{
// Check if the last value is float.
static_assert(std::same_as<float, seqan3::pack_traits::back<int, float, bool, int, float>>);
}

◆ drop

template<ptrdiff_t i, typename... pack_t>
using seqan3::pack_traits::drop = typedef typename decltype(detail::split_after<i, pack_t...>(type_list<>{}))::second_type

Return a seqan3::type_list of the types in the type pack, except the first n.

Template Parameters
iThe amount to drop; must be >= 0 and <= the size of the type pack.
pack_tThe type pack.

(Compile-time) Complexity

  • Number of template instantiations: O(n)
  • Other operations: O(n)
// 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()
{
// Drop the first two types in the pack.
static_assert(std::same_as<seqan3::type_list<bool, int>, seqan3::pack_traits::drop<2, float, double, bool, int>>);
}
typename decltype(detail::split_after< i, pack_t... >(type_list<>{}))::second_type drop
Return a seqan3::type_list of the types in the type pack, except the first n.
Definition type_pack/traits.hpp:367

◆ drop_front

template<typename... pack_t>
using seqan3::pack_traits::drop_front = typedef typename decltype(detail::drop_front<pack_t...>())::type

Return a seqan3::type_list of all the types in the type pack, except the first.

Template Parameters
pack_tThe type pack.

(Compile-time) Complexity

  • Number of template instantiations: O(1)
  • Other operations: O(1)
// 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()
{
// Return the a type list of the pack without the first type.
static_assert(
std::same_as<seqan3::type_list<float, bool, int>, seqan3::pack_traits::drop_front<int, float, bool, int>>);
}
typename decltype(detail::drop_front< pack_t... >())::type drop_front
Return a seqan3::type_list of all the types in the type pack, except the first.
Definition type_pack/traits.hpp:305

◆ drop_last

template<ptrdiff_t i, typename... pack_t>
using seqan3::pack_traits::drop_last = typedef take<size<pack_t...> - i, pack_t...>

Return a seqan3::type_list of the types the type pack, except the last n.

Template Parameters
iThe amount to drop; must be >= 0 and <= the size of the type pack.
pack_tThe type pack.

(Compile-time) Complexity

  • Number of template instantiations: O(n)
  • Other operations: O(n)
// 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()
{
// Take the last two types in the pack.
static_assert(std::same_as<seqan3::type_list<bool, int>, seqan3::pack_traits::take_last<2, int, float, bool, int>>);
}
drop< size< pack_t... > - i, pack_t... > take_last
Return a seqan3::type_list of the last n types in the type pack.
Definition type_pack/traits.hpp:385

◆ front

template<typename... pack_t>
using seqan3::pack_traits::front = typedef typename decltype(detail::front<pack_t...>())::type

Return the first type from the type pack.

Template Parameters
pack_tThe type pack.

(Compile-time) Complexity

  • Number of template instantiations: O(1)
  • Other operations: O(1)
// 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()
{
// Check if the first value is int.
static_assert(std::same_as<int, seqan3::pack_traits::front<int, float, bool, int, float>>);
}

◆ replace_at

template<typename replace_t , std::ptrdiff_t i, typename... pack_t>
using seqan3::pack_traits::replace_at = typedef decltype(detail::replace_at<replace_t, i, pack_t...>(std::make_index_sequence<size<pack_t...> >{}))

Replace the type at the given index with the given type.

Template Parameters
replace_tThe type to replace the old type with.
iThe index of the type to be replaced.
pack_tThe (input) type pack.

(Compile-time) Complexity

  • Number of template instantiations: O(n)
  • Other operations: O(n)
// 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()
{
// Take the last two types in the pack.
static_assert(std::same_as<seqan3::type_list<bool, int>, seqan3::pack_traits::take_last<2, int, float, bool, int>>);
}

◆ split_after

template<ptrdiff_t i, typename... pack_t>
using seqan3::pack_traits::split_after = typedef decltype(detail::split_after<i, pack_t...>(type_list<>{}))

Split a type pack into two parts returned as a pair of seqan3::type_list.

Template Parameters
iThe number of elements after which to split; must be >= 0 and <= the size of the type pack.
pack_tThe type pack.

(Compile-time) Complexity

  • Number of template instantiations: O(n)
  • Other operations: O(n)
// 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()
{
// Take the last two types in the pack.
static_assert(std::same_as<seqan3::type_list<bool, int>, seqan3::pack_traits::take_last<2, int, float, bool, int>>);
}

◆ take

template<ptrdiff_t i, typename... pack_t>
using seqan3::pack_traits::take = typedef typename decltype(detail::split_after<i, pack_t...>(type_list<>{}))::first_type

Return a seqan3::type_list of the first n types in the type pack.

Template Parameters
iThe target size; must be >= 0 and <= the size of the type pack.
pack_tThe type pack.

(Compile-time) Complexity

  • Number of template instantiations: O(n)
  • Other operations: O(n)
// 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()
{
// Take the first two types in the pack.
static_assert(std::same_as<seqan3::type_list<int, float>, seqan3::pack_traits::take<2, int, float, bool, double>>);
}
typename decltype(detail::split_after< i, pack_t... >(type_list<>{}))::first_type take
Return a seqan3::type_list of the first n types in the type pack.
Definition type_pack/traits.hpp:349

◆ take_last

template<ptrdiff_t i, typename... pack_t>
using seqan3::pack_traits::take_last = typedef drop<size<pack_t...> - i, pack_t...>

Return a seqan3::type_list of the last n types in the type pack.

Template Parameters
iThe target size; must be >= 0 and <= the size of the type pack.
pack_tThe type pack.

(Compile-time) Complexity

  • Number of template instantiations: O(n)
  • Other operations: O(n)
// 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()
{
// Take the last two types in the pack.
static_assert(std::same_as<seqan3::type_list<bool, int>, seqan3::pack_traits::take_last<2, int, float, bool, int>>);
}

◆ transform

template<template< typename > typename trait_t, typename... pack_t>
using seqan3::pack_traits::transform = typedef seqan3::type_list<trait_t<pack_t>...>

Apply a transformation trait to every type in the pack and return a seqan3::type_list of the results.

Template Parameters
trait_tThe transformation trait, can be an alias template, e.g. a transformation trait shortcut.
pack_tThe type pack.

The transformation trait given as first argument can be an alias template, e.g. std::type_identity_t, not std::type_identity. The alias must take exactly one argument and be defined for all types in the pack.

(Compile-time) Complexity

  • Number of template instantiations: O(n)
  • Other operations: O(1)
// 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 <list>
#include <vector>
int main()
{
// Transform the types in the pack into reference types.
static_assert(std::same_as<
seqan3::pack_traits::
transform<std::ranges::range_reference_t, std::vector<int>, std::vector<float>, std::list<bool>>,
}
Provides various transformation traits used by the range module.
Type that contains multiple types.
Definition type_list.hpp:26

Function Documentation

◆ all_of()

template<typename unary_predicate_t , typename... pack_t>
requires (std::predicate<unary_predicate_t, pack_t> && ...)
constexpr bool seqan3::detail::all_of ( unary_predicate_t &&  fn,
pack_t &&...  args 
)
constexpr

Tests whether a given predicate evaluates to true for each element in the function parameter pack.

Template Parameters
unary_predicate_tThe function type, like function pointers, functors and lambdas; must model std::predicate expanded on each argument type.
pack_tThe parameter pack of the arguments (each argument type can be different).
Parameters
[in]fnThe predicate to evaluate for every argument.
[in]argsThe parameter pack.
Returns
true if the predicate returns true for each type in the type list, false otherwise.

This function behaves like std::all_of but on parameter packs. The invocation(s) will be done without any loop.

Example

// 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 <type_traits>
// With c++20 you could also write it like this
// auto fn = []<typename value_t>(value_t && value)
// {
// ...
// };
auto fn = [](auto value)
{
// id is the original type not wrapped in std::type_identity.
using value_t = decltype(value);
if constexpr (std::is_same_v<value_t, bool>)
return value == false;
else if constexpr (std::is_same_v<value_t, int>)
return value == 3;
else if constexpr (std::is_same_v<value_t, double>)
return value - 1.2 < 0.00001;
else
return false;
};
static_assert(seqan3::detail::all_of(fn, 3, 1.2, false)); // evaluates to true
static_assert(!seqan3::detail::all_of(fn, 3, 1.2, false, "something else")); // evaluates to false
constexpr bool all_of(unary_predicate_t &&fn)
Tests whether a given predicate evaluates to true for each type in a seqan3::type_list.
Definition type_list_algorithm.hpp:107
Provides algorithms for meta programming, parameter packs and seqan3::type_list.

Complexity

Linear in the number of elements in the pack.

Attention
Opposed to the std::all_of the argument order is changed, such that the first argument is the unary predicate to invoke on each argument followed by the arguments. This is due to a constraint in the c++ language regarding parameter packs.
See also
https://en.cppreference.com/w/cpp/language/parameter_pack

◆ at()

template<ptrdiff_t idx, typename head_t , typename... tail_t>
auto seqan3::pack_traits::detail::at ( )

Implementation for seqan3::pack_traits::at.

Template Parameters
idxThe index.
head_tCurrently viewed pack_t element.
tail_tRest of the type pack.

◆ drop_front()

template<typename head_t , typename... tail_t>
type_list< tail_t... > seqan3::pack_traits::detail::drop_front ( )

Implementation for seqan3::pack_traits::drop_front.

Template Parameters
head_tCurrently viewed pack_t element.
tail_tRest of the type pack.

◆ find()

template<typename query_t , typename... pack_t>
constexpr ptrdiff_t seqan3::pack_traits::detail::find ( )
constexpr

Implementation for seqan3::pack_traits::find.

Template Parameters
query_tThe type you are searching for.
pack_tThe type pack.
Returns
The position of the first occurrence of query_t in pack_t or -1 if it is not contained.

◆ find_if()

template<template< typename > typename pred_t, typename... pack_t>
constexpr ptrdiff_t seqan3::pack_traits::detail::find_if ( )
constexpr

Implementation for seqan3::pack_traits::find_if.

Template Parameters
pred_tThe predicate that is being evaluated.
pack_tThe type pack.
Returns
The position of the first type t in pack_t for whom pred_t<t>::value is true.

◆ for_each()

template<typename unary_function_t , typename... pack_t>
requires (std::invocable<unary_function_t, pack_t> && ...)
constexpr void seqan3::detail::for_each ( unary_function_t &&  fn,
pack_t &&...  args 
)
constexpr

Applies a function to each element of the given function parameter pack.

Template Parameters
unary_function_tThe function type, like function pointers, functors and lambdas.
pack_tThe parameter pack of the arguments (each argument type can be different).
Parameters
[in]fnThe function to call on every argument.
[in]argsThe parameter pack.

This function behaves like std::for_each but on parameter packs. The invocation(s) will be done without any loop.

Example

// 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>
int main()
{
auto fn = [](auto && a)
{
};
// prints each argument, i.e. "0, 1, 2, 3\n"
seqan3::detail::for_each(fn, 0, ", ", 1.0, ", ", std::string{"2, 3"}, '\n');
// is the same as explicitly writing
fn(0);
fn(", ");
fn(1.0);
fn(", ");
fn(std::string{"2, 3"});
fn('\n');
return 0;
}
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
constexpr void for_each(unary_function_t &&fn)
Applies a function element wise to all types of a type list.
Definition type_list_algorithm.hpp:157

Complexity

Linear in the number of elements in the pack.

Attention
Opposed to the std::for_each the argument order is changed, such that the first argument is the unary function to invoke on each argument followed by the arguments. This is due to a constraint in the c++ language regarding parameter packs.
See also
https://en.cppreference.com/w/cpp/language/parameter_pack

◆ front()

template<typename head_t , typename... tail_t>
std::type_identity< head_t > seqan3::pack_traits::detail::front ( )

Implementation for seqan3::pack_traits::front.

Template Parameters
head_tCurrently viewed pack_t element.
tail_tRest of the type pack.

◆ replace_at()

template<typename replace_t , ptrdiff_t idx, typename... pack_t, size_t... i>
auto seqan3::pack_traits::detail::replace_at ( std::index_sequence< i... >  ) -> type_list< std::conditional_t< i==idx, replace_t, pack_t >... >

Implementation for seqan3::pack_traits::replace_at.

Template Parameters
replace_tThe type replacing the old one.
idxThe index of the type to replace.
pack_tThe type pack to be modified.
iThe indicies of the index sequence associated with the type pack.

◆ split_after()

template<ptrdiff_t idx, typename head_t , typename... pack2_t, typename... pack1_t>
auto seqan3::pack_traits::detail::split_after ( type_list< pack1_t... >  )

Implementation for seqan3::pack_traits::split_after.

Template Parameters
idxThe index to split the type pack at.
pack1_tThe type pack before the split index.
head_tThe next type that is moved before split index.
pack2_tThe type pack after the split index.

Variable Documentation

◆ contains

template<typename query_t , typename... pack_t>
constexpr bool seqan3::pack_traits::contains = (find<query_t, pack_t...> != -1)
inlineconstexpr

Whether a type occurs in a pack or not.

Template Parameters
query_tThe type you are searching for.
pack_tThe type pack.
Returns
true or false.

(Compile-time) Complexity

  • Number of template instantiations: O(1)
  • Other operations: O(n), possibly == i, where i is the index of the first occurrence
// 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()
{
// Double is not in the pack so find returns -1. However, bool is in the pack so find will return 2.
static_assert(seqan3::pack_traits::find<double, int, float, bool> == -1);
static_assert(seqan3::pack_traits::find<bool, int, float, bool> == 2);
}

◆ count

template<typename query_t , typename... pack_t>
constexpr ptrdiff_t seqan3::pack_traits::count = (std::is_same_v<query_t, pack_t> + ... + 0)
inlineconstexpr

Count the occurrences of a type in a pack.

Template Parameters
query_tThe type you are searching for.
pack_tThe type pack.
Returns
The number of occurrences of the query_t in pack_t.

(Compile-time) Complexity

  • Number of template instantiations: O(1)
  • Other operations: O(n)
// 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()
{
// Count the number of type int in the pack.
static_assert(seqan3::pack_traits::count<int, int, float, bool, int> == 2);
}

◆ find

template<typename query_t , typename... pack_t>
constexpr ptrdiff_t seqan3::pack_traits::find = seqan3::pack_traits::detail::find<query_t, pack_t...>()
inlineconstexpr

Get the index of the first occurrence of a type in a pack.

Template Parameters
query_tThe type you are searching for.
pack_tThe type pack.
Returns
The position of the first occurrence of query_t in pack_t or -1 if it is not contained.

(Compile-time) Complexity

  • Number of template instantiations: O(1)
  • Other operations: O(n), possibly == i, where i is the return value
// 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()
{
// Double is not in the pack so find returns -1. However, bool is in the pack so find will return 2.
static_assert(seqan3::pack_traits::find<double, int, float, bool> == -1);
static_assert(seqan3::pack_traits::find<bool, int, float, bool> == 2);
}

◆ find_if

template<template< typename > typename pred_t, typename... pack_t>
constexpr ptrdiff_t seqan3::pack_traits::find_if = seqan3::pack_traits::detail::find_if<pred_t, pack_t...>()
inlineconstexpr

Get the index of the first type in a pack that satisfies the given predicate.

Template Parameters
pred_tThe predicate that is being evaluated (a class template).
pack_tThe type pack.
Returns
The index or -1 if no types match.

Note that the predicate must be given as a type template (variable templates cannot be passed as template arguments unfortunately). This means e.g. find_if<std::is_integral, float, double, int, float> (not std::is_integral_v!).

(Compile-time) Complexity

  • Number of template instantiations: O(n), possibly == i, where i is the return value
  • Other operations: O(n), possibly == i, where i is the return value

    Only the predicate is instantiated.

// 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()
{
// None of the types in t is a pointer so find_if returns -1. However, int and bool are both integral,
// so find_if returns 0 for the first occurrence.
static_assert(seqan3::pack_traits::find_if<std::is_pointer, int, float, double> == -1);
static_assert(seqan3::pack_traits::find_if<std::is_integral, int, float, double> == 0);
}

◆ size

template<typename... pack_t>
constexpr size_t seqan3::pack_traits::size = sizeof...(pack_t)
inlineconstexpr

The size of a type pack.

Template Parameters
pack_tThe type pack.
Returns
sizeof...(pack_t)

(Compile-time) Complexity

  • Number of template instantiations: O(1)
  • Other operations: O(1)
// 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()
{
// Get the size of the pack.
static_assert(seqan3::pack_traits::size<int, float, bool, int> == 4);
}
Hide me