Loading...
Searching...
No Matches
type_list/traits.hpp
Go to the documentation of this file.
// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: BSD-3-Clause
#pragma once
#include <type_traits>
#include <seqan3/utility/type_list/type_list.hpp>
#include <seqan3/utility/type_pack/traits.hpp>
// ----------------------------------------------------------------------------
// seqan3::list_traits::detail
// ----------------------------------------------------------------------------
namespace seqan3::list_traits::detail
{
template <ptrdiff_t idx, typename... pack_t>
std::type_identity<seqan3::pack_traits::at<idx, pack_t...>> at(type_list<pack_t...>);
template <typename... pack_t>
std::type_identity<seqan3::pack_traits::front<pack_t...>> front(type_list<pack_t...>);
template <typename... pack_t>
std::type_identity<seqan3::pack_traits::back<pack_t...>> back(type_list<pack_t...>);
template <typename... pack1_t, typename... pack2_t>
type_list<pack1_t..., pack2_t...> concat(type_list<pack1_t...>, type_list<pack2_t...>);
template <typename... pack1_t, typename... pack2_t, typename... more_lists_t>
auto concat(type_list<pack1_t...>, type_list<pack2_t...>, more_lists_t...)
{
return concat(type_list<pack1_t..., pack2_t...>{}, more_lists_t{}...);
}
template <typename... pack_t>
pack_traits::drop_front<pack_t...> drop_front(type_list<pack_t...>);
template <template <typename> typename trait_t, typename... pack_t>
pack_traits::transform<trait_t, pack_t...> transform(type_list<pack_t...>);
template <ptrdiff_t idx, typename... pack1_t>
pack_traits::split_after<idx, pack1_t...> split_after(type_list<pack1_t...>);
template <size_t count, typename t>
auto repeat()
{
if constexpr (count == 0)
return type_list<>{};
else if constexpr (count == 1)
return type_list<t>{};
else if constexpr (count == 2)
return type_list<t, t>{};
else if constexpr (count == 3)
return type_list<t, t, t>{};
else if constexpr (count == 4)
return type_list<t, t, t, t>{};
else if constexpr (count == 5)
return type_list<t, t, t, t, t>{};
else
return concat(repeat<5, t>(), repeat<count - 5, t>());
}
template <typename replace_t, ptrdiff_t idx, typename... pack_t>
pack_traits::replace_at<replace_t, idx, pack_t...> replace_at(type_list<pack_t...>);
inline constexpr type_list<> reverse(type_list<>)
{
return {};
}
template <typename head_t, typename... pack_t>
auto reverse(type_list<head_t, pack_t...>)
{
return concat(reverse(type_list<pack_t...>{}), type_list<head_t>{});
}
template <typename... current_list_t>
constexpr seqan3::type_list<current_list_t...> type_list_difference(seqan3::type_list<current_list_t...>,
seqan3::type_list<>)
{
return {};
}
template <typename... current_list_t, typename remove_t, typename... remove_list_t>
constexpr auto type_list_difference(seqan3::type_list<current_list_t...>, seqan3::type_list<remove_t, remove_list_t...>)
{
constexpr auto pos = seqan3::pack_traits::find<remove_t, current_list_t...>;
if constexpr (pos >= 0)
{
using split_list_t = seqan3::pack_traits::split_after<pos, current_list_t...>;
using split_list1_t = typename split_list_t::first_type;
using split_list2_t = decltype(drop_front(typename split_list_t::second_type{}));
using filtered_list_t = decltype(concat(split_list1_t{}, split_list2_t{}));
return type_list_difference(filtered_list_t{}, seqan3::type_list<remove_t, remove_list_t...>{});
}
else
{
// remove_t not contained in current_list_t
using filtered_list_t = seqan3::type_list<current_list_t...>;
return type_list_difference(filtered_list_t{}, seqan3::type_list<remove_list_t...>{});
}
}
} // namespace seqan3::list_traits::detail
// ----------------------------------------------------------------------------
// seqan3::list_traits
// ----------------------------------------------------------------------------
namespace seqan3::list_traits
{
template <typename list_t>
requires seqan3::detail::template_specialisation_of<list_t, seqan3::type_list>
inline constexpr size_t size = 0;
template <typename... pack_t>
inline constexpr size_t size<type_list<pack_t...>> = sizeof...(pack_t);
template <typename query_t, typename list_t>
requires seqan3::detail::template_specialisation_of<list_t, seqan3::type_list>
inline constexpr ptrdiff_t count = -1;
template <typename query_t, typename... pack_t>
inline constexpr ptrdiff_t count<query_t, type_list<pack_t...>> = seqan3::pack_traits::count<query_t, pack_t...>;
template <typename query_t, typename list_t>
requires seqan3::detail::template_specialisation_of<list_t, seqan3::type_list>
inline constexpr ptrdiff_t find = -1;
template <typename query_t, typename... pack_t>
inline constexpr ptrdiff_t find<query_t, type_list<pack_t...>> =
seqan3::pack_traits::detail::find<query_t, pack_t...>();
template <template <typename> typename pred_t, typename list_t>
requires seqan3::detail::template_specialisation_of<list_t, seqan3::type_list>
inline constexpr ptrdiff_t find_if = -1;
template <template <typename> typename pred_t, typename... pack_t>
inline constexpr ptrdiff_t find_if<pred_t, type_list<pack_t...>> =
seqan3::pack_traits::detail::find_if<pred_t, pack_t...>();
template <typename query_t, typename list_t>
requires seqan3::detail::template_specialisation_of<list_t, seqan3::type_list>
inline constexpr bool contains = (find<query_t, list_t> != -1);
template <ptrdiff_t idx, typename list_t>
requires (seqan3::detail::template_specialisation_of<list_t, seqan3::type_list>)
&& ((idx >= 0 && idx < size<list_t>) || (-idx <= size<list_t>))
using at = typename decltype(detail::at<idx>(list_t{}))::type;
template <typename list_t>
requires (seqan3::detail::template_specialisation_of<list_t, seqan3::type_list>) && (size<list_t> > 0)
using front = typename decltype(detail::front(list_t{}))::type;
template <typename list_t>
requires (seqan3::detail::template_specialisation_of<list_t, seqan3::type_list>) && (size<list_t> > 0)
using back = typename decltype(detail::back(list_t{}))::type;
template <typename... lists_t>
requires (seqan3::detail::template_specialisation_of<lists_t, seqan3::type_list> && ...)
using concat = decltype(detail::concat(lists_t{}...));
template <typename list_t>
requires (seqan3::detail::template_specialisation_of<list_t, seqan3::type_list>) && (size<list_t> > 0)
using drop_front = decltype(detail::drop_front(list_t{}));
template <ptrdiff_t i, typename list_t>
requires (seqan3::detail::template_specialisation_of<list_t, seqan3::type_list>) && (i >= 0 && i <= size<list_t>)
using take = typename decltype(detail::split_after<i>(list_t{}))::first_type;
template <ptrdiff_t i, typename list_t>
requires (seqan3::detail::template_specialisation_of<list_t, seqan3::type_list>) && (i >= 0 && i <= size<list_t>)
using drop = typename decltype(detail::split_after<i>(list_t{}))::second_type;
template <ptrdiff_t i, typename list_t>
requires (seqan3::detail::template_specialisation_of<list_t, seqan3::type_list>) && (i >= 0 && i <= size<list_t>)
using take_last = drop<size<list_t> - i, list_t>;
template <ptrdiff_t i, typename list_t>
requires (seqan3::detail::template_specialisation_of<list_t, seqan3::type_list>) && (i >= 0 && i <= size<list_t>)
using drop_last = take<size<list_t> - i, list_t>;
template <ptrdiff_t i, typename list_t>
requires (seqan3::detail::template_specialisation_of<list_t, seqan3::type_list>) && (i >= 0 && i <= size<list_t>)
using split_after = decltype(detail::split_after<i>(list_t{}));
template <template <typename> typename trait_t, typename list_t>
requires seqan3::detail::template_specialisation_of<list_t, seqan3::type_list>
using transform = decltype(detail::transform<trait_t>(list_t{}));
template <typename replace_t, std::ptrdiff_t i, typename list_t>
requires (seqan3::detail::template_specialisation_of<list_t, seqan3::type_list>) && (i >= 0 && i < size<list_t>)
using replace_at = decltype(detail::replace_at<replace_t, i>(list_t{}));
template <size_t count, typename t>
using repeat = decltype(detail::repeat<count, t>());
} // namespace seqan3::list_traits
seqan3::list_traits::replace_at
decltype(detail::replace_at< replace_t, i >(list_t{})) replace_at
Replace the type at the given index with the given type.
Definition type_list/traits.hpp:486
seqan3::list_traits::front
typename decltype(detail::front(list_t{}))::type front
Return the first type from the type list.
Definition type_list/traits.hpp:293
seqan3::list_traits::transform
decltype(detail::transform< trait_t >(list_t{})) transform
Apply a transformation trait to every type in the list and return a seqan3::type_list of the results.
Definition type_list/traits.hpp:467
seqan3::list_traits::drop_last
take< size< list_t > - i, list_t > drop_last
Return a seqan3::type_list of the types the input type list, except the last n.
Definition type_list/traits.hpp:428
seqan3::list_traits::contains
constexpr bool contains
Whether a type occurs in a type list or not.
Definition type_list/traits.hpp:249
seqan3::list_traits::take_last
drop< size< list_t > - i, list_t > take_last
Return a seqan3::type_list of the last n types in the input type list.
Definition type_list/traits.hpp:410
seqan3::list_traits::drop_front
decltype(detail::drop_front(list_t{})) drop_front
Return a seqan3::type_list of all the types in the type list, except the first.
Definition type_list/traits.hpp:356
seqan3::list_traits::detail::back
std::type_identity< seqan3::pack_traits::back< pack_t... > > back(type_list< pack_t... >)
Implementation for seqan3::list_traits::back.
seqan3::list_traits::split_after
decltype(detail::split_after< i >(list_t{})) split_after
Split a seqan3::type_list into two parts returned as a pair of seqan3::type_list.
Definition type_list/traits.hpp:446
seqan3::list_traits::detail::drop_front
pack_traits::drop_front< pack_t... > drop_front(type_list< pack_t... >)
Implementation for seqan3::list_traits::drop_front.
seqan3::list_traits::detail::repeat
auto repeat()
Implementation for seqan3::list_traits::repeat.
Definition type_list/traits.hpp:95
seqan3::list_traits::detail::transform
pack_traits::transform< trait_t, pack_t... > transform(type_list< pack_t... >)
Implementation for seqan3::list_traits::transform.
seqan3::list_traits::detail::at
std::type_identity< seqan3::pack_traits::at< idx, pack_t... > > at(type_list< pack_t... >)
Implementation for seqan3::list_traits::at.
seqan3::list_traits::at
typename decltype(detail::at< idx >(list_t{}))::type at
Return the type at given index from the type list.
Definition type_list/traits.hpp:276
seqan3::list_traits::detail::split_after
pack_traits::split_after< idx, pack1_t... > split_after(type_list< pack1_t... >)
Implementation for seqan3::list_traits::split_after.
seqan3::list_traits::take
typename decltype(detail::split_after< i >(list_t{}))::first_type take
Return a seqan3::type_list of the first n types in the input type list.
Definition type_list/traits.hpp:374
seqan3::list_traits::detail::replace_at
pack_traits::replace_at< replace_t, idx, pack_t... > replace_at(type_list< pack_t... >)
Implementation for seqan3::list_traits::replace_at.
seqan3::list_traits::detail::front
std::type_identity< seqan3::pack_traits::front< pack_t... > > front(type_list< pack_t... >)
Implementation for seqan3::list_traits::front.
seqan3::list_traits::concat
decltype(detail::concat(lists_t{}...)) concat
Join two seqan3::type_list s into one.
Definition type_list/traits.hpp:339
seqan3::list_traits::detail::concat
type_list< pack1_t..., pack2_t... > concat(type_list< pack1_t... >, type_list< pack2_t... >)
Implementation for seqan3::list_traits::concat.
seqan3::list_traits::drop
typename decltype(detail::split_after< i >(list_t{}))::second_type drop
Return a seqan3::type_list of the types in the input type list, except the first n.
Definition type_list/traits.hpp:392
seqan3::list_traits::back
typename decltype(detail::back(list_t{}))::type back
Return the last type from the type list.
Definition type_list/traits.hpp:313
seqan3::list_traits::repeat
decltype(detail::repeat< count, t >()) repeat
Create a type list with the given type repeated count times..
Definition type_list/traits.hpp:501
seqan3::pack_traits::at
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
seqan3::pack_traits::find
constexpr ptrdiff_t find
Get the index of the first occurrence of a type in a pack.
Definition type_pack/traits.hpp:179
seqan3::pack_traits::count
constexpr ptrdiff_t count
Count the occurrences of a type in a pack.
Definition type_pack/traits.hpp:161
seqan3::pack_traits::drop_front
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
seqan3::pack_traits::front
typename decltype(detail::front< pack_t... >())::type front
Return the first type from the type pack.
Definition type_pack/traits.hpp:262
seqan3::pack_traits::detail::find_if
constexpr ptrdiff_t find_if()
Implementation for seqan3::pack_traits::find_if.
Definition type_pack/traits.hpp:44
seqan3::pack_traits::split_after
decltype(detail::split_after< i, pack_t... >(type_list<>{})) split_after
Split a type pack into two parts returned as a pair of seqan3::type_list.
Definition type_pack/traits.hpp:421
seqan3::pack_traits::detail::find
constexpr ptrdiff_t find()
Implementation for seqan3::pack_traits::find.
Definition type_pack/traits.hpp:31
seqan3::pack_traits::replace_at
decltype(detail::replace_at< replace_t, i, pack_t... >(std::make_index_sequence< size< pack_t... > >{})) replace_at
Replace the type at the given index with the given type.
Definition type_pack/traits.hpp:440
seqan3::pack_traits::back
typename decltype((std::type_identity< pack_t >{},...))::type back
Return the last type from the type pack.
Definition type_pack/traits.hpp:282
seqan3::pack_traits::transform
seqan3::type_list< trait_t< pack_t >... > transform
Apply a transformation trait to every type in the pack and return a seqan3::type_list of the results.
Definition type_pack/traits.hpp:325
seqan3::list_traits
Namespace containing traits for working on seqan3::type_list.
seqan3::type_list
Type that contains multiple types.
Definition type_list.hpp:26
seqan3::list_traits::detail::type_list_difference
constexpr seqan3::type_list< current_list_t... > type_list_difference(seqan3::type_list< current_list_t... >, seqan3::type_list<>)
Constructs the multiset difference list1 \ list2 [recursion anchor].
Definition type_list/traits.hpp:137
seqan3::list_traits::detail::reverse
constexpr type_list reverse(type_list<>)
A replacement for meta::reverse [recursion anchor].
Definition type_list/traits.hpp:123
type_list.hpp
Provides seqan3::type_list.
traits.hpp
Provides various traits for template packs.
type_traits
Hide me