Skip to content

Commit

Permalink
[MISC] Add new concept template_specialisation_of.
Browse files Browse the repository at this point in the history
Signed-off-by: Lydia Buntrock <lydia.buntrock@fu-berlin.de>
  • Loading branch information
Irallia committed Dec 9, 2020
1 parent c812a00 commit 32f602a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
31 changes: 31 additions & 0 deletions include/seqan3/core/detail/template_inspection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

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

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

// ----------------------------------------------------------------------------
// template_specialisation_of
// ----------------------------------------------------------------------------

/*!\addtogroup concept
* \{
*/

/*!\interface seqan3::template_specialisation_of <>
* \brief Provides concept `seqan3::template_specialisation_of<mytype, [...]>` for checking the type specialisation of
* some type with a given template, for example a specialized `type_list<float>` with the `type_list` template.
*
* \ingroup type_traits
*
* \tparam mytype The query type.
* \tparam type_template The type template you wish to compare against mytype.
*
* \see seqan3::detail::is_type_specialisation_of_v
*
* ### Example
*
* \include test/snippet/core/detail/template_inspection_usage_3.cpp
*/
//!\cond
template <typename mytype, template <typename ...> typename type_template>
SEQAN3_CONCEPT template_specialisation_of = is_type_specialisation_of_v<mytype, type_template>;

//!\endcond
//!\}

// ----------------------------------------------------------------------------
// strip_type_identity
// ----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion test/snippet/core/detail/template_inspection_usage_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ int main()
{
using my_type = std::vector<int>;

if constexpr (seqan3::detail::is_type_specialisation_of_v<my_type, std::vector>) // std::vector has no <> !
if constexpr (seqan3::detail::is_type_specialisation_of_v<my_type, std::vector>) // Note: std::vector has no <> !
{
// ...
}
Expand Down
13 changes: 13 additions & 0 deletions test/snippet/core/detail/template_inspection_usage_3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <vector>

#include <seqan3/core/detail/template_inspection.hpp>

int main()
{
using my_type = std::vector<int>;

if constexpr (seqan3::detail::template_specialisation_of<my_type, std::vector>) // Note: std::vector has no <> !
{
// ...
}
}
6 changes: 6 additions & 0 deletions test/unit/core/detail/template_inspection_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,9 @@ TEST(template_inspect, is_type_specialisation_of_with_ill_formed_non_type_templa
{
EXPECT_FALSE((seqan3::detail::is_value_specialisation_of_v<vargs_foo<5>, constraint_vbar>));
}

TEST(template_inspect, template_specialisation_of)
{
EXPECT_TRUE((seqan3::detail::template_specialisation_of<seqan3::type_list<float>, seqan3::type_list>));
EXPECT_FALSE((seqan3::detail::template_specialisation_of<seqan3::type_list<int>, std::tuple>));
}

0 comments on commit 32f602a

Please sign in to comment.