Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r70199 - in sandbox/enums/boost/enums: . scoped
From: vicente.botet_at_[hidden]
Date: 2011-03-19 12:43:48


Author: viboes
Date: 2011-03-19 12:43:46 EDT (Sat, 19 Mar 2011)
New Revision: 70199
URL: http://svn.boost.org/trac/boost/changeset/70199

Log:
Enums: Added is_enum<> meta-function
Added:
   sandbox/enums/boost/enums/scoped/is_enum.hpp (contents, props changed)
Text files modified:
   sandbox/enums/boost/enums/scoped.hpp | 1
   sandbox/enums/boost/enums/scoped/emulation.hpp | 46 +++++++++++++++++++++++++--------------
   sandbox/enums/boost/enums/scoped/scoping_type.hpp | 12 +++++-----
   3 files changed, 36 insertions(+), 23 deletions(-)

Modified: sandbox/enums/boost/enums/scoped.hpp
==============================================================================
--- sandbox/enums/boost/enums/scoped.hpp (original)
+++ sandbox/enums/boost/enums/scoped.hpp 2011-03-19 12:43:46 EDT (Sat, 19 Mar 2011)
@@ -30,6 +30,7 @@
 #include <boost/enums/scoped/default_value.hpp>
 #include <boost/enums/scoped/native_value.hpp>
 #include <boost/enums/scoped/underlying_value.hpp>
+#include <boost/enums/scoped/is_enum.hpp>
 
     
 #endif // BOOST_ENUMS_SCOPED_HPP

Modified: sandbox/enums/boost/enums/scoped/emulation.hpp
==============================================================================
--- sandbox/enums/boost/enums/scoped/emulation.hpp (original)
+++ sandbox/enums/boost/enums/scoped/emulation.hpp 2011-03-19 12:43:46 EDT (Sat, 19 Mar 2011)
@@ -19,6 +19,7 @@
 #include <boost/enums/scoped/default_value.hpp>
 #include <boost/enums/scoped/native_value.hpp>
 #include <boost/enums/scoped/underlying_value.hpp>
+#include <boost/enums/scoped/is_enum.hpp>
 #include <boost/conversion/convert_to.hpp>
 #include <boost/preprocessor/if.hpp>
 #include <boost/preprocessor/empty.hpp>
@@ -55,25 +56,35 @@
 
 #else // !defined(BOOST_NO_SCOPED_ENUMS) && ! defined(BOOST_NO_SCOPED_ENUMS_COMPARE)
 
- #define BOOST_ENUMS_DETAIL_COMPARAISON_OPERATORS(EC, UT) \
- BOOST_ENUMS_DETAIL_BINARY_OPERATOR(EC, UT, ==) \
- BOOST_ENUMS_DETAIL_BINARY_OPERATOR(EC, UT, !=) \
- BOOST_ENUMS_DETAIL_BINARY_OPERATOR(EC, UT, <) \
- BOOST_ENUMS_DETAIL_BINARY_OPERATOR(EC, UT, <=) \
- BOOST_ENUMS_DETAIL_BINARY_OPERATOR(EC, UT, >) \
+ #define BOOST_ENUMS_DETAIL_COMPARAISON_OPERATORS(EC, UT) \
+ BOOST_ENUMS_DETAIL_BINARY_OPERATOR(EC, UT, ==) \
+ BOOST_ENUMS_DETAIL_BINARY_OPERATOR(EC, UT, !=) \
+ BOOST_ENUMS_DETAIL_BINARY_OPERATOR(EC, UT, <) \
+ BOOST_ENUMS_DETAIL_BINARY_OPERATOR(EC, UT, <=) \
+ BOOST_ENUMS_DETAIL_BINARY_OPERATOR(EC, UT, >) \
       BOOST_ENUMS_DETAIL_BINARY_OPERATOR(EC, UT, >=)
 
 #endif // !defined(BOOST_NO_SCOPED_ENUMS) && ! defined(BOOST_NO_SCOPED_ENUMS_COMPARE)
 
- #define BOOST_ENUMS_DETAIL_SCOPING_TYPE_SPEC(EC) \
- namespace boost { \
- namespace enums { \
- template <> \
- struct scoping_type<native_type<EC>::type> \
- { \
- typedef EC type; \
- }; \
- } \
+ #define BOOST_ENUMS_DETAIL_SCOPING_TYPE_SPEC(EC) \
+ namespace boost { \
+ namespace enums { \
+ template <> \
+ struct scoping_type<native_type<EC>::type> \
+ { \
+ typedef EC type; \
+ }; \
+ } \
+ }
+
+ #define BOOST_ENUMS_DETAIL_IS_ENUM_TYPE_SPEC(EC) \
+ namespace boost { \
+ namespace enums { \
+ template <> \
+ struct is_enum<EC> : mpl::true_ \
+ { \
+ }; \
+ } \
       }
 
 #ifndef BOOST_NO_SCOPED_ENUMS
@@ -297,8 +308,9 @@
     BOOST_ENUMS_DETAIL_END_2(EC, UT) \
   };
 
-#define BOOST_ENUMS_SPECIALIZATIONS(EC, UT) \
- BOOST_ENUMS_DETAIL_SCOPING_TYPE_SPEC(EC)
+#define BOOST_ENUMS_SPECIALIZATIONS(EC, UT) \
+ BOOST_ENUMS_DETAIL_SCOPING_TYPE_SPEC(EC) \
+ BOOST_ENUMS_DETAIL_IS_ENUM_TYPE_SPEC(EC)
 
 
 #endif // BOOST_ENUMS_SCOPED_EMULATION_HPP

Added: sandbox/enums/boost/enums/scoped/is_enum.hpp
==============================================================================
--- (empty file)
+++ sandbox/enums/boost/enums/scoped/is_enum.hpp 2011-03-19 12:43:46 EDT (Sat, 19 Mar 2011)
@@ -0,0 +1,62 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2011.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/enums for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+/*!
+ \file
+ \brief
+ This header defines the is_enum meta-function that replace std::is_enum when we want to take care of the scoped enum emulation.
+ */
+
+#ifndef BOOST_ENUMS_SCOPED_IS_ENUM_HPP
+#define BOOST_ENUMS_SCOPED_IS_ENUM_HPP
+
+#include <boost/config.hpp>
+#include <boost/mpl/or.hpp>
+#include <boost/mpl/bool.hpp>
+#include <boost/type_traits/is_enum.hpp>
+
+namespace boost
+{
+ namespace enums
+ {
+ /*! meta-function configuring emulated enums.
+ */
+ template <typename T>
+ struct is_emulated_enum : mpl::false_
+ {
+ //! the result of this meta-function is false by default.
+ //! is_emulated_enum must be specialized for each emulated enum.
+ };
+
+ /*! meta-function checking if his parameter is a builtin or emulated enum, that is can be used as an emulated enum.
+ */
+ template <typename T>
+ struct is_enum
+#ifdef BOOST_ENUMS_DOXYGEN_INVOKED
+ //! The member \c value states whether \c T can be used as an enum.
+ //! When scoped enums are not supported it is defined as \c std::is_enum<T>::value or \c is_emulated_enum<T>::value.
+ //! Otherwise is defined as \c std::is_enum<T>::value.
+ : bool_type
+#else
+ #ifdef BOOST_NO_SCOPED_ENUMS
+ : mpl::or_<boost::is_enum<T>, is_emulated_enum<T> >
+ #else
+ : boost::is_enum<T>
+ #endif
+#endif
+ {
+
+ };
+ }
+}
+
+#endif // BOOST_ENUMS_SCOPED_IS_ENUM_HPP

Modified: sandbox/enums/boost/enums/scoped/scoping_type.hpp
==============================================================================
--- sandbox/enums/boost/enums/scoped/scoping_type.hpp (original)
+++ sandbox/enums/boost/enums/scoped/scoping_type.hpp 2011-03-19 12:43:46 EDT (Sat, 19 Mar 2011)
@@ -30,12 +30,12 @@
      This meta-function must be specialized for each enum class.
      */
     template <typename EC_type>
- struct scoping_type
- {
- //! Depending on whethere the compiler supports scoped enums or nor the nested type must be the same type or the emulated one.
- //! By default this metafunction defines it as if scoped enums where supported so the specialization will be needed only when emulation is needed.
- typedef EC_type type;
- };
+ struct scoping_type
+ {
+ //! Depending on whethere the compiler supports scoped enums or nor the nested type must be the same type or the emulated one.
+ //! By default this metafunction defines it as if scoped enums where supported so the specialization will be needed only when emulation is needed.
+ typedef EC_type type;
+ };
   }
 }
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk