Dune::Std::to_false_type< T > Class Template Reference

template mapping a type to std::false_type More...

#include <dune/common/std/type_traits.hh>


Detailed Description

template<typename T>
class Dune::Std::to_false_type< T >

template mapping a type to std::false_type

Template Parameters:
T Some type

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
  {
    static_assert(false,
                  "Instanciating this non-specialized template is an "
                  "error. You should use one of the specializations "
                  "instead.");
    typedef void FrobnicateType;
  };

This will trigger 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 to_false_type: replace false by to_false_type<T>::value, like this:

  template<typename T>
  struct Traits
  {
    static_assert(Std::to_false_type<T>::value,
                  "Instanciating this non-specialized template is an "
                  "error. You should use one of the specializations "
                  "instead.");
    typedef void FrobnicateType;
  };

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


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 25 Mar 2018 for dune-common by  doxygen 1.6.1