[Insight-developers] The time has come for itkTypeTraits.h?

kent williams norman-k-williams at uiowa.edu
Fri Nov 5 15:11:37 EDT 2010


In trying to replace the use of typeids in ITK with compile-time code based
on Template Metaprogramming, I've run into this issue: The job would be a
whole lot easier if we had access to the C++0x type_traits header.

What would it take to make this a possibility?

In CMakeLists.txt:

CHECK_INCLUDE_FILES(type_traits HAVE_TYPE_TRAITS)

itkTypeTraits.h:

#ifndef __itkTypeTraits_h
#define __itkTypeTraits_h
#include "itkConfigure.h"

#if defined(HAVE_TYPE_TRAITS)
#include <type_traits>
#else
// implement needed type_traits macros
namespace std
{
  template<typename _Tp, _Tp __v>
    struct integral_constant
    {
      static const _Tp                      value = __v;
      typedef _Tp                           value_type;
      typedef integral_constant<_Tp, __v>   type;
    };
  typedef integral_constant<bool, true>     true_type;
  typedef integral_constant<bool, false>    false_type;

// e.g. the is_same relation
template<typename, typename>
struct is_same : public false_type { };

template<typename _Tp>
struct is_same<_Tp, _Tp>  : public true_type { };

}
#endif



More information about the Insight-developers mailing list