Dune Core Modules (2.3.1)

Dune::AlwaysFalse< T > Struct Template Reference

template which always yields a false value More...

#include <dune/common/static_assert.hh>

Static Public Attributes

static const bool value = false
 always a false value
 

Detailed Description

template<typename T>
struct Dune::AlwaysFalse< T >

template which always yields a false value

Template Parameters
TSome type. It sould be a type expression involving template parameters of the class or function using AlwaysFalse.

Suppose you have a template class. You want to document the required members of this class in the non-specialized template, but you know that actually instantiating the non-specialized template is an error. You can try something like this:

template<typename T>
struct Traits {
"Instanciating this non-specialized template is an "
"error. You should use one of the specializations "
"instead.");
typedef void FrobnicateType;
};
#define dune_static_assert(COND, MSG)
Helper template so that compilation fails if condition is not true.
Definition: static_assert.hh:79

This will trigger dune_static_assert() as soon as the compiler reads the definition for the Traits template, since it knows that "false" can never become true, no matter what the template parameters of Traits are. As a workaround you can use AlwaysFalse: replace false by AlwaysFalse<T>::value, like this:

template<typename T>
struct Traits {
"Instanciating this non-specialized template is an "
"error. You should use one of the specializations "
"instead.");
typedef void FrobnicateType;
};
template which always yields a false value
Definition: static_assert.hh:127

Since there might be an specialization of AlwaysFalse for template parameter T, the compiler cannot trigger dune_static_assert() until the type of T is known, that is, until Traits<T> is instantiated.


The documentation for this struct was generated from the following file:
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)