BioC++ core-0.7.0
The Modern C++ libraries for Bioinformatics.
 
Loading...
Searching...
No Matches
template_inspection.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2022 deCODE Genetics
3// Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
4// Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik
5// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
6// shipped with this file and also available at: https://github.com/biocpp/biocpp-core/blob/main/LICENSE.md
7// -----------------------------------------------------------------------------------------------------
8
14#pragma once
15
16#include <concepts>
17
19
20namespace bio::meta
21{
22
23// ----------------------------------------------------------------------------
24// transfer_template_args_onto
25// ----------------------------------------------------------------------------
26
28template <typename source_type, template <typename...> typename target_template>
29struct transfer_template_args_onto
30{};
32
57template <template <typename...> typename source_template,
58 template <typename...>
59 typename target_template,
60 typename... source_arg_types>
61 requires(requires() { typename target_template<source_arg_types...>; })
62struct transfer_template_args_onto<source_template<source_arg_types...>, target_template>
63{
65 using type = target_template<source_arg_types...>;
66};
67
72template <typename source_type, template <typename...> typename target_template>
73using transfer_template_args_onto_t = typename transfer_template_args_onto<source_type, target_template>::type;
74
75// ----------------------------------------------------------------------------
76// transfer_template_vargs_onto
77// ----------------------------------------------------------------------------
78
80template <typename source_type, template <auto...> typename target_template>
81struct transfer_template_vargs_onto
82{};
84
102template <template <auto...> typename source_template,
103 template <auto...>
104 typename target_template,
105 auto... source_varg_types>
106 requires(requires() { typename target_template<source_varg_types...>; })
107struct transfer_template_vargs_onto<source_template<source_varg_types...>, target_template>
108{
110 using type = target_template<source_varg_types...>;
111};
112
117template <typename source_type, template <auto...> typename target_template>
118using transfer_template_vargs_onto_t = typename transfer_template_vargs_onto<source_type, target_template>::type;
119
120// ----------------------------------------------------------------------------
121// is_type_specialisation_of_v
122// ----------------------------------------------------------------------------
123
136template <typename source_t, template <typename...> typename target_template>
138{};
139
141template <typename source_t, template <typename...> typename target_template>
142 requires(
143 !std::same_as<transformation_trait_or_t<transfer_template_args_onto<source_t, target_template>, void>, void>)
146{};
147
153template <typename source_t, template <typename...> typename target_template>
154inline constexpr bool is_type_specialisation_of_v = is_type_specialisation_of<source_t, target_template>::value;
155
156// ----------------------------------------------------------------------------
157// template_specialisation_of
158// ----------------------------------------------------------------------------
159
174template <typename mytype, template <typename...> typename type_template>
175concept template_specialisation_of = is_type_specialisation_of_v<mytype, type_template>;
176
177// ----------------------------------------------------------------------------
178// is_value_specialisation_of_v
179// ----------------------------------------------------------------------------
180
182template <typename source_t, template <auto...> typename target_template>
183struct is_value_specialisation_of : std::false_type
184{};
186
196template <typename source_t, template <auto...> typename target_template>
197 requires(
198 !std::same_as<transformation_trait_or_t<transfer_template_vargs_onto<source_t, target_template>, void>, void>)
199struct is_value_specialisation_of<source_t, target_template> :
201{};
202
208template <typename source_t, template <auto...> typename target_template>
209inline constexpr bool is_value_specialisation_of_v = is_value_specialisation_of<source_t, target_template>::value;
210
220template <typename fallback_t, template <typename...> typename templ_t, typename... spec_t>
222{
224 using type = fallback_t;
225};
226
228template <typename fallback_t, template <typename...> typename templ_t, typename... spec_t>
229 requires(requires { typename templ_t<spec_t...>; })
231{
233 using type = templ_t<spec_t...>;
234};
235
243template <typename fallback_t, template <typename...> typename templ_t, typename... spec_t>
244using valid_template_spec_or_t = typename valid_template_spec_or<fallback_t, templ_t, spec_t...>::type;
245
246// ----------------------------------------------------------------------------
247// strip_type_identity
248// ----------------------------------------------------------------------------
249
254template <typename t>
257
258} // namespace bio::meta
typename valid_template_spec_or< fallback_t, templ_t, spec_t... >::type valid_template_spec_or_t
Helper for bio::meta::valid_template_spec_or (transformation_trait shortcut).
Definition: template_inspection.hpp:244
typename transfer_template_args_onto< source_type, target_template >::type transfer_template_args_onto_t
Shortcut for bio::meta::transfer_template_args_onto (transformation_trait shortcut).
Definition: template_inspection.hpp:73
typename transformation_trait_or< type_t, default_t >::type transformation_trait_or_t
Helper type of bio::meta::transformation_trait_or (transformation_trait shortcut).
Definition: transformation_trait_or.hpp:53
typename transfer_template_vargs_onto< source_type, target_template >::type transfer_template_vargs_onto_t
Shortcut for bio::meta::transfer_template_vargs_onto (transformation_trait shortcut).
Definition: template_inspection.hpp:118
The Meta module's namespace.
Determines whether a source_type is a specialisation of another template.
Definition: template_inspection.hpp:138
target_template< source_arg_types... > type
The return type: the target type specialised by the unpacked types in the list.
Definition: template_inspection.hpp:65
target_template< source_varg_types... > type
The return type: the target type specialised by the unpacked types in the list.
Definition: template_inspection.hpp:110
templ_t< spec_t... > type
The resulting type.
Definition: template_inspection.hpp:233
Exposes templ_t<spec_t...> if that is valid, otherwise fallback_t.
Definition: template_inspection.hpp:222
fallback_t type
The resulting type.
Definition: template_inspection.hpp:224
constexpr bool is_type_specialisation_of_v
Helper variable template for bio::meta::detail::is_type_specialisation_of (unary_type_trait shortcut)...
Definition: template_inspection.hpp:154
constexpr bool is_value_specialisation_of_v
Helper variable template for bio::meta::is_value_specialisation_of (unary_type_trait shortcut).
Definition: template_inspection.hpp:209
Provides bio::meta::transformation_trait_or.