Provides metaprogramming utilities for working on template parameter packs.
More...
|
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. More...
|
|
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. More...
|
|
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. More...
|
|
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 . More...
|
|
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. More...
|
|
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 . More...
|
|
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. More...
|
|
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. More...
|
|
|
template<typename ... pack_t> |
constexpr size_t | seqan3::pack_traits::size = sizeof...(pack_t) |
| The size of a type pack. More...
|
|
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. More...
|
|
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. More...
|
|
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. More...
|
|
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. More...
|
|
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>
.
◆ at [no-api]
Return the type at given index from the type pack.
- Template Parameters
-
idx | The index; must be smaller than the size of the pack. |
pack_t | The 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)
int main()
{
static_assert(std::same_as<float, 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: traits.hpp:256
Provides various traits for template packs.
◆ back [no-api]
Return the last type from the type pack.
- Template Parameters
-
(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).
int main()
{
static_assert(std::same_as<float, seqan3::pack_traits::back<int, float, bool, int, float>>);
}
◆ drop [no-api]
Return a seqan3::type_list of the types in the type pack, except the first n
.
- Template Parameters
-
i | The amount to drop; must be >= 0 and <= the size of the type pack. |
pack_t | The type pack. |
(Compile-time) Complexity
- Number of template instantiations: O(n)
- Other operations: O(n)
int main()
{
}
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: traits.hpp:388
◆ drop_front [no-api]
Return a seqan3::type_list of all the types in the type pack, except the first.
- Template Parameters
-
(Compile-time) Complexity
- Number of template instantiations: O(1)
- Other operations: O(1)
int main()
{
static_assert(std::same_as<seqan3::type_list<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: traits.hpp:322
◆ drop_last [no-api]
Return a seqan3::type_list of the types the type pack, except the last n
.
- Template Parameters
-
i | The amount to drop; must be >= 0 and <= the size of the type pack. |
pack_t | The type pack. |
(Compile-time) Complexity
- Number of template instantiations: O(n)
- Other operations: O(n)
int main()
{
}
drop< size< pack_t... > - i, pack_t... > take_last
Return a seqan3::type_list of the last n types in the type pack.
Definition: traits.hpp:408
◆ front [no-api]
Return the first type from the type pack.
- Template Parameters
-
(Compile-time) Complexity
- Number of template instantiations: O(1)
- Other operations: O(1)
int main()
{
static_assert(std::same_as<int, seqan3::pack_traits::front<int, float, bool, int, float>>);
}
◆ replace_at [no-api]
Replace the type at the given index with the given type.
- Template Parameters
-
replace_t | The type to replace the old type with. |
i | The index of the type to be replaced. |
pack_t | The (input) type pack. |
(Compile-time) Complexity
- Number of template instantiations: O(n)
- Other operations: O(n)
◆ split_after [no-api]
Split a type pack into two parts returned as a pair of seqan3::type_list.
- Template Parameters
-
i | The number of elements after which to split; must be >= 0 and <= the size of the type pack. |
pack_t | The type pack. |
(Compile-time) Complexity
- Number of template instantiations: O(n)
- Other operations: O(n)
◆ take [no-api]
Return a seqan3::type_list of the first n
types in the type pack.
- Template Parameters
-
i | The target size; must be >= 0 and <= the size of the type pack. |
pack_t | The type pack. |
(Compile-time) Complexity
- Number of template instantiations: O(n)
- Other operations: O(n)
int main()
{
}
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: traits.hpp:368
◆ take_last [no-api]
Return a seqan3::type_list of the last n
types in the type pack.
- Template Parameters
-
i | The target size; must be >= 0 and <= the size of the type pack. |
pack_t | The type pack. |
(Compile-time) Complexity
- Number of template instantiations: O(n)
- Other operations: O(n)
◆ transform [no-api]
Apply a transformation trait to every type in the pack and return a seqan3::type_list of the results.
- Template Parameters
-
trait_t | The transformation trait, can be an alias template, e.g. a transformation trait shortcut. |
pack_t | The 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)
int main()
{
static_assert(std::same_as<seqan3::pack_traits::transform<std::ranges::range_reference_t, std::vector<int>,
}
Provides various transformation traits used by the range module.
Type that contains multiple types.
Definition: type_list.hpp:29
◆ contains [no-api]
template<typename query_t , typename ... pack_t>
constexpr bool seqan3::pack_traits::contains = (find<query_t, pack_t...> != -1) |
|
no-apiinlineconstexpr |
Whether a type occurs in a pack or not.
- Template Parameters
-
query_t | The type you are searching for. |
pack_t | The 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
int main()
{
static_assert(seqan3::pack_traits::find<double, int, float, bool> == -1);
static_assert(seqan3::pack_traits::find<bool, int, float, bool> == 2);
}
◆ count [no-api]
template<typename query_t , typename ... pack_t>
constexpr ptrdiff_t seqan3::pack_traits::count = (std::is_same_v<query_t, pack_t> + ... + 0) |
|
no-apiinlineconstexpr |
Count the occurrences of a type in a pack.
- Template Parameters
-
query_t | The type you are searching for. |
pack_t | The 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)
int main()
{
static_assert(seqan3::pack_traits::count<int, int, float, bool, int> == 2);
}
◆ find [no-api]
template<typename query_t , typename ... pack_t>
constexpr ptrdiff_t seqan3::pack_traits::find = seqan3::pack_traits::detail::find<query_t, pack_t...>() |
|
no-apiinlineconstexpr |
Get the index of the first occurrence of a type in a pack.
- Template Parameters
-
query_t | The type you are searching for. |
pack_t | The 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
int main()
{
static_assert(seqan3::pack_traits::find<double, int, float, bool> == -1);
static_assert(seqan3::pack_traits::find<bool, int, float, bool> == 2);
}
◆ find_if [no-api]
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...>() |
|
no-apiinlineconstexpr |
Get the index of the first type in a pack that satisfies the given predicate.
- Template Parameters
-
pred_t | The predicate that is being evaluated (a class template). |
pack_t | The 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.
int main()
{
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 [no-api]
template<typename ... pack_t>
constexpr size_t seqan3::pack_traits::size = sizeof...(pack_t) |
|
no-apiinlineconstexpr |
The size of a type pack.
- Template Parameters
-
- Returns
sizeof...(pack_t)
(Compile-time) Complexity
- Number of template instantiations: O(1)
- Other operations: O(1)
int main()
{
static_assert(seqan3::pack_traits::size<int, float, bool, int> == 4);
}