Skip to content

Commit 32f602a

Browse files
committed
[MISC] Add new concept template_specialisation_of.
Signed-off-by: Lydia Buntrock <lydia.buntrock@fu-berlin.de>
1 parent c812a00 commit 32f602a

4 files changed

Lines changed: 51 additions & 1 deletion

File tree

include/seqan3/core/detail/template_inspection.hpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
/*!\file
99
* \author Hannes Hauswedell <hannes.hauswedell AT fu-berlin.de>
10+
* \author Lydia Buntrock <lydia.buntrock AT fu-berlin.de>
1011
* \brief Provides type traits for working with templates.
1112
*/
1213

@@ -235,6 +236,36 @@ struct valid_template_spec_or<fallback_t, templ_t, spec_t...>
235236
template <typename fallback_t, template <typename ...> typename templ_t, typename ...spec_t>
236237
using valid_template_spec_or_t = typename valid_template_spec_or<fallback_t, templ_t, spec_t...>::type;
237238

239+
// ----------------------------------------------------------------------------
240+
// template_specialisation_of
241+
// ----------------------------------------------------------------------------
242+
243+
/*!\addtogroup concept
244+
* \{
245+
*/
246+
247+
/*!\interface seqan3::template_specialisation_of <>
248+
* \brief Provides concept `seqan3::template_specialisation_of<mytype, [...]>` for checking the type specialisation of
249+
* some type with a given template, for example a specialized `type_list<float>` with the `type_list` template.
250+
*
251+
* \ingroup type_traits
252+
*
253+
* \tparam mytype The query type.
254+
* \tparam type_template The type template you wish to compare against mytype.
255+
*
256+
* \see seqan3::detail::is_type_specialisation_of_v
257+
*
258+
* ### Example
259+
*
260+
* \include test/snippet/core/detail/template_inspection_usage_3.cpp
261+
*/
262+
//!\cond
263+
template <typename mytype, template <typename ...> typename type_template>
264+
SEQAN3_CONCEPT template_specialisation_of = is_type_specialisation_of_v<mytype, type_template>;
265+
266+
//!\endcond
267+
//!\}
268+
238269
// ----------------------------------------------------------------------------
239270
// strip_type_identity
240271
// ----------------------------------------------------------------------------

test/snippet/core/detail/template_inspection_usage_2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ int main()
66
{
77
using my_type = std::vector<int>;
88

9-
if constexpr (seqan3::detail::is_type_specialisation_of_v<my_type, std::vector>) // std::vector has no <> !
9+
if constexpr (seqan3::detail::is_type_specialisation_of_v<my_type, std::vector>) // Note: std::vector has no <> !
1010
{
1111
// ...
1212
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <vector>
2+
3+
#include <seqan3/core/detail/template_inspection.hpp>
4+
5+
int main()
6+
{
7+
using my_type = std::vector<int>;
8+
9+
if constexpr (seqan3::detail::template_specialisation_of<my_type, std::vector>) // Note: std::vector has no <> !
10+
{
11+
// ...
12+
}
13+
}

test/unit/core/detail/template_inspection_test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,9 @@ TEST(template_inspect, is_type_specialisation_of_with_ill_formed_non_type_templa
190190
{
191191
EXPECT_FALSE((seqan3::detail::is_value_specialisation_of_v<vargs_foo<5>, constraint_vbar>));
192192
}
193+
194+
TEST(template_inspect, template_specialisation_of)
195+
{
196+
EXPECT_TRUE((seqan3::detail::template_specialisation_of<seqan3::type_list<float>, seqan3::type_list>));
197+
EXPECT_FALSE((seqan3::detail::template_specialisation_of<seqan3::type_list<int>, std::tuple>));
198+
}

0 commit comments

Comments
 (0)