From 2f272b99c600a192ad605583ef69553aec944aad Mon Sep 17 00:00:00 2001 From: Jorrit Fahlke <joe@dune-project.org> Date: Fri, 28 May 2010 14:21:44 +0000 Subject: [PATCH] [typetraits.hh] Add implementation of integral_constant. If there is an implementation available in std or std::tr1 we fall back to that. [[Imported from SVN: r6022]] --- dune/common/typetraits.hh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/dune/common/typetraits.hh b/dune/common/typetraits.hh index 1ca6af741..12ca20197 100644 --- a/dune/common/typetraits.hh +++ b/dune/common/typetraits.hh @@ -369,6 +369,43 @@ namespace Dune { typedef T2 Type; }; + + //////////////////////////////////////////////////////////////////////// + // + // integral_constant (C++0x 20.7.3 "Helper classes") + // +#if defined HAVE_TYPE_TRAITS + using std::integral_constant; + using std::true_type; + using std::false_type; +#elif defined HAVE_TR1_TYPE_TRAITS + using std::tr1::integral_constant; + using std::tr1::true_type; + using std::tr1::false_type; +#else + //! Generate a type for a given integral constant + /** + * \tparam T Type of the constant. + * \tparam v Value of the constant. + */ + template <class T, T v> + struct integral_constant { + //! value this type was generated for + static const T value = v; + //! type of value + typedef T value_type; + //! type of this class itself + typedef integral_constant<T,v> type; + //! conversion to value_type/T + operator value_type() { return value; } + }; + + //! type for true + typedef integral_constant<bool, true> true_type; + //! type for false + typedef integral_constant<bool, false> false_type; +#endif + /** @} */ } #endif -- GitLab