SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
seqan3::detail::is_class_template_declarable_with< query_t, args_t > Struct Template Reference

An unary type trait that tests whether a template class can be declared with the given template type parameters. More...

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

+ Inheritance diagram for seqan3::detail::is_class_template_declarable_with< query_t, args_t >:

Related Symbols

(Note that these are not member symbols.)

template<template< typename... > typename query_t, typename... args_t>
constexpr bool is_class_template_declarable_with_v
 Helper variable template for seqan3::detail::is_class_template_declarable_with.
 

Detailed Description

template<template< typename... > typename query_t, typename... args_t>
struct seqan3::detail::is_class_template_declarable_with< query_t, args_t >

An unary type trait that tests whether a template class can be declared with the given template type parameters.

Template Parameters
query_tThe type of the template class to test.
args_tThe template parameter pack to instantiate the template class with.

Note, this unary type trait can be used in a seqan3::detail::lazy_conditional expression to check if instantiating a template class with specific template arguments would result in a valid template declaration. Thus, the template parameters of the checked class must be constrained accordingly. It is, however, not possible to test if the the resulting type is incomplete or not, such that it can not be tested if an instance of the class template with the given template arguments can be actually created.

Example

// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <type_traits>
template <typename t>
requires std::is_integral_v<t>
struct foo
{
t value;
};
// foo is declarable with int, i.e. foo<int> is a valid expression
static_assert(seqan3::detail::is_class_template_declarable_with_v<foo, int>);
// foo is not declarable with double, because it does not fulfil the requires clause of foo.
static_assert(!seqan3::detail::is_class_template_declarable_with_v<foo, double>);
// This also works with std::enable_if and producing a substitution failure.
template <typename t, typename = std::enable_if_t<std::is_same_v<t, int>>>
struct bar
{
t value;
};
// bar is declarable with int, i.e. bar<int> is a valid expression
static_assert(seqan3::detail::is_class_template_declarable_with_v<bar, int>);
// bar is not declarable with double, because it produces an substitution failure (SFINAE).
static_assert(!seqan3::detail::is_class_template_declarable_with_v<bar, double>);
// is_class_template_declarable_with_v works well with lazy_conditional_t
template <typename t>
using maybe_foo_t = seqan3::detail::
lazy_conditional_t<seqan3::detail::is_class_template_declarable_with_v<foo, t>, seqan3::detail::lazy<foo, t>, t>;
int main()
{
foo<int> a = maybe_foo_t<int>{10}; // foo is instantiable with int, thus use foo<int>
seqan3::debug_stream << "a: " << a.value << '\n'; // prints 10
float b = maybe_foo_t<float>{0.4f}; // foo is not instantiable with float, thus use float directly
seqan3::debug_stream << "b: " << b << '\n'; // prints 0.4
return 0;
}
Includes the aligned_sequence and the related insert_gap and erase_gap functions to enable stl contai...
Provides seqan3::debug_stream and related types.
debug_stream_type debug_stream
A global instance of seqan3::debug_stream_type.
Definition debug_stream.hpp:37
Provides a type trait for verifying valid template declarations.
An empty type whose only purpose is to hold an uninstantiated template plus its arguments.
Definition lazy_conditional.hpp:30

Friends And Related Symbol Documentation

◆ is_class_template_declarable_with_v

template<template< typename... > typename query_t, typename... args_t>
template<template< typename... > typename query_t, typename... args_t>
constexpr bool is_class_template_declarable_with_v
related
Initial value:
=
is_class_template_declarable_with<query_t, args_t...>::value

Helper variable template for seqan3::detail::is_class_template_declarable_with.

Template Parameters
query_tThe type of the template class to test.
args_tThe template parameter pack to instantiate the template class with.

The documentation for this struct was generated from the following file:
Hide me