Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r69574 - in sandbox/enums/boost/enums: . mpl
From: vicente.botet_at_[hidden]
Date: 2011-03-04 19:34:25


Author: viboes
Date: 2011-03-04 19:34:21 EST (Fri, 04 Mar 2011)
New Revision: 69574
URL: http://svn.boost.org/trac/boost/changeset/69574

Log:
Enums: Added mpl enum_c_tag, enum_c, and meta functions comparisons
+ use of constexpr when applicable
Added:
   sandbox/enums/boost/enums/mpl/
   sandbox/enums/boost/enums/mpl/comparison.hpp (contents, props changed)
   sandbox/enums/boost/enums/mpl/enum_c.hpp (contents, props changed)
   sandbox/enums/boost/enums/mpl/enum_c_tag.hpp (contents, props changed)
   sandbox/enums/boost/enums/mpl/equal_to.hpp (contents, props changed)
   sandbox/enums/boost/enums/mpl/greater.hpp (contents, props changed)
   sandbox/enums/boost/enums/mpl/greater_equal.hpp (contents, props changed)
   sandbox/enums/boost/enums/mpl/less.hpp (contents, props changed)
   sandbox/enums/boost/enums/mpl/less_equal.hpp (contents, props changed)
   sandbox/enums/boost/enums/mpl/numeric_cast.hpp (contents, props changed)
Text files modified:
   sandbox/enums/boost/enums/emulation.hpp | 8 ++++----
   sandbox/enums/boost/enums/first.hpp | 6 +++---
   sandbox/enums/boost/enums/last.hpp | 6 +++---
   sandbox/enums/boost/enums/pred.hpp | 12 ++++++------
   sandbox/enums/boost/enums/succ.hpp | 12 ++++++------
   5 files changed, 22 insertions(+), 22 deletions(-)

Modified: sandbox/enums/boost/enums/emulation.hpp
==============================================================================
--- sandbox/enums/boost/enums/emulation.hpp (original)
+++ sandbox/enums/boost/enums/emulation.hpp 2011-03-04 19:34:21 EST (Fri, 04 Mar 2011)
@@ -37,7 +37,7 @@
 
 #ifndef BOOST_NO_SCOPED_ENUMS
     #define BOOST_ENUMS_DETAIL_BINARY_OPERATOR(EC, UT, OP) \
- inline bool operator OP(EC lhs, EC rhs) { \
+ inline BOOST_CONSTEXPR bool operator OP(EC lhs, EC rhs) { \
         return (boost::enums::underlying_type<EC>::type)(lhs) \
         OP \
         (boost::enums::underlying_type<EC>::type)(rhs); \
@@ -46,13 +46,13 @@
 #else // BOOST_NO_SCOPED_ENUMS
 
   #define BOOST_ENUMS_DETAIL_BINARY_OPERATOR(EC, UT, OP) \
- friend inline bool operator OP(EC lhs, EC rhs) { \
+ friend inline BOOST_CONSTEXPR bool operator OP(EC lhs, EC rhs) { \
         return lhs.get() OP rhs.get(); \
       } \
- friend inline bool operator OP(type lhs, EC rhs) { \
+ friend inline BOOST_CONSTEXPR bool operator OP(type lhs, EC rhs) { \
         return lhs OP rhs.get(); \
       } \
- friend inline bool operator OP(EC lhs, type rhs) { \
+ friend inline BOOST_CONSTEXPR bool operator OP(EC lhs, type rhs) { \
         return lhs.get() OP rhs; \
       }
 

Modified: sandbox/enums/boost/enums/first.hpp
==============================================================================
--- sandbox/enums/boost/enums/first.hpp (original)
+++ sandbox/enums/boost/enums/first.hpp 2011-03-04 19:34:21 EST (Fri, 04 Mar 2011)
@@ -20,13 +20,13 @@
   namespace enums {
     namespace meta {
       template <typename EC>
- struct first
+ struct first
       {
- static const typename enum_type<EC>::type value = enums::meta::val<EC,0>::value;
+ BOOST_STATIC_CONSTEXPR typename enum_type<EC>::type value = enums::meta::val<EC,0>::value;
       };
     }
     template <typename EC>
- EC first()
+ BOOST_CONSTEXPR EC first()
     {
         return meta::val<EC,0>::value;
     }

Modified: sandbox/enums/boost/enums/last.hpp
==============================================================================
--- sandbox/enums/boost/enums/last.hpp (original)
+++ sandbox/enums/boost/enums/last.hpp 2011-03-04 19:34:21 EST (Fri, 04 Mar 2011)
@@ -21,13 +21,13 @@
   namespace enums {
     namespace meta {
       template <typename EC>
- struct last
+ struct last
       {
- static const typename enum_type<EC>::type value = val<EC,size<EC>::value-1>::value;
+ BOOST_STATIC_CONSTEXPR typename enum_type<EC>::type value = val<EC,size<EC>::value-1>::value;
       };
     }
     template <typename EC>
- EC last()
+ BOOST_CONSTEXPR EC last()
     {
         return meta::val<EC,meta::size<EC>::value-1>::value;
     }

Added: sandbox/enums/boost/enums/mpl/comparison.hpp
==============================================================================
--- (empty file)
+++ sandbox/enums/boost/enums/mpl/comparison.hpp 2011-03-04 19:34:21 EST (Fri, 04 Mar 2011)
@@ -0,0 +1,29 @@
+// comparison.hpp ---------------------------------------------------------------//
+//
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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.
+//
+// Adapted from libcxx tests
+//
+//////////////////////////////////////////////////////////////////////////////
+
+
+
+#ifndef BOOST_ENUMS_MPL_COMPARISON_HPP
+#define BOOST_ENUMS_MPL_COMPARISON_HPP
+
+#include <boost/enums/mpl/equal_to.hpp>
+#include <boost/enums/mpl/not_equal_to.hpp>
+#include <boost/enums/mpl/less.hpp>
+#include <boost/enums/mpl/less_equal.hpp>
+#include <boost/enums/mpl/greater.hpp>
+#include <boost/enums/mpl/greater_equal.hpp>
+
+#endif // BOOST_ENUMS_MPL_COMPARISON_HPP

Added: sandbox/enums/boost/enums/mpl/enum_c.hpp
==============================================================================
--- (empty file)
+++ sandbox/enums/boost/enums/mpl/enum_c.hpp 2011-03-04 19:34:21 EST (Fri, 04 Mar 2011)
@@ -0,0 +1,36 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_ENUMS_ENUM_C_HPP
+#define BOOST_ENUMS_ENUM_C_HPP
+
+#include <boost/enums/mpl/enum_c_tag.hpp>
+#include <boost/enums/enum_type.hpp>
+#include <boost/enums/underlying_type.hpp>
+#include <cstddef>
+
+namespace boost {
+ namespace mpl {
+ template <typename EC, typename enums::enum_type<EC>::type V>
+ struct enum_c {
+ typedef enum_c_tag tag;
+ BOOST_STATIC_CONSTEXPR typename enums::enum_type<EC>::type value = V;
+ typedef enum_c type;
+ typedef typename enums::enum_type<EC>::type value_type;
+ typedef typename enums::underlying_type<EC>::type underlying_type;
+ operator value_type() const { return this->value; }
+ };
+
+ }
+}
+
+#endif

Added: sandbox/enums/boost/enums/mpl/enum_c_tag.hpp
==============================================================================
--- (empty file)
+++ sandbox/enums/boost/enums/mpl/enum_c_tag.hpp 2011-03-04 19:34:21 EST (Fri, 04 Mar 2011)
@@ -0,0 +1,30 @@
+// abs.hpp
+//
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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.
+//
+// Adapted from libcxx tests
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_ENUMS_MPL_ENUM_C_TAG_HPP
+#define BOOST_ENUMS_MPL_ENUM_C_TAG_HPP
+
+#include <boost/mpl/int.hpp>
+
+namespace boost {
+namespace mpl {
+
+struct enum_c_tag : int_<11> {};
+
+}
+}
+
+#endif // BOOST_ENUMS_MPL_ENUM_C_TAG_HPP

Added: sandbox/enums/boost/enums/mpl/equal_to.hpp
==============================================================================
--- (empty file)
+++ sandbox/enums/boost/enums/mpl/equal_to.hpp 2011-03-04 19:34:21 EST (Fri, 04 Mar 2011)
@@ -0,0 +1,42 @@
+// equal_to.hpp
+//
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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.
+//
+// Adapted from libcxx tests
+//
+//////////////////////////////////////////////////////////////////////////////
+
+
+#ifndef BOOST_ENUMS_MPL_EQUAL_TO_HPP
+#define BOOST_ENUMS_MPL_EQUAL_TO_HPP
+
+#include <boost/enums/mpl/enum_c_tag.hpp>
+#include <boost/mpl/integral_c.hpp>
+#include <boost/mpl/equal_to.hpp>
+
+namespace boost {
+namespace mpl {
+
+template<>
+struct equal_to_impl< enum_c_tag,enum_c_tag >
+{
+ template< typename E1, typename E2 > struct apply
+ : equal_to<
+ integral_c<typename E1::underlying_type, (typename E1::underlying_type)(E1::value)>,
+ integral_c<typename E2::underlying_type, (typename E2::underlying_type)(E2::value)>
+ >
+ {
+ };
+};
+}
+}
+
+#endif // BOOST_ENUMS_MPL_EQUAL_TO_HPP

Added: sandbox/enums/boost/enums/mpl/greater.hpp
==============================================================================
--- (empty file)
+++ sandbox/enums/boost/enums/mpl/greater.hpp 2011-03-04 19:34:21 EST (Fri, 04 Mar 2011)
@@ -0,0 +1,42 @@
+// greater.hpp
+//
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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.
+//
+// Adapted from libcxx tests
+//
+//////////////////////////////////////////////////////////////////////////////
+
+
+#ifndef BOOST_ENUMS_MPL_GREATER_HPP
+#define BOOST_ENUMS_MPL_GREATER_HPP
+
+#include <boost/enums/mpl/enum_c_tag.hpp>
+#include <boost/mpl/integral_c.hpp>
+#include <boost/mpl/greater.hpp>
+
+namespace boost {
+namespace mpl {
+
+template<>
+struct greater_impl< enum_c_tag,enum_c_tag >
+{
+ template< typename R1, typename R2 > struct apply
+ : greater<
+ integral_c<typename E1::underlying_type, (typename E1::underlying_type)(E1::value)>,
+ integral_c<typename E2::underlying_type, (typename E2::underlying_type)(E2::value)>
+ >
+ {
+ };
+};
+}
+}
+
+#endif // BOOST_ENUMS_MPL_GREATER_HPP

Added: sandbox/enums/boost/enums/mpl/greater_equal.hpp
==============================================================================
--- (empty file)
+++ sandbox/enums/boost/enums/mpl/greater_equal.hpp 2011-03-04 19:34:21 EST (Fri, 04 Mar 2011)
@@ -0,0 +1,42 @@
+// greater_equal.hpp
+//
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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.
+//
+// Adapted from libcxx tests
+//
+//////////////////////////////////////////////////////////////////////////////
+
+
+#ifndef BOOST_ENUMS_MPL_GREATER_EQUAL_HPP
+#define BOOST_ENUMS_MPL_GREATER_EQUAL_HPP
+
+#include <boost/enums/mpl/enum_c_tag.hpp>
+#include <boost/mpl/integral_c.hpp>
+#include <boost/mpl/greater_equal.hpp>
+
+namespace boost {
+namespace mpl {
+
+template<>
+struct greater_equal_impl< enum_c_tag,enum_c_tag >
+{
+ template< typename R1, typename R2 > struct apply
+ : greater_equal<
+ integral_c<typename E1::underlying_type, (typename E1::underlying_type)(E1::value)>,
+ integral_c<typename E2::underlying_type, (typename E2::underlying_type)(E2::value)>
+ >
+ {
+ };
+};
+}
+}
+
+#endif // BOOST_ENUMS_MPL_GREATER_EQUAL_HPP

Added: sandbox/enums/boost/enums/mpl/less.hpp
==============================================================================
--- (empty file)
+++ sandbox/enums/boost/enums/mpl/less.hpp 2011-03-04 19:34:21 EST (Fri, 04 Mar 2011)
@@ -0,0 +1,42 @@
+// less.hpp
+//
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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.
+//
+// Adapted from libcxx tests
+//
+//////////////////////////////////////////////////////////////////////////////
+
+
+#ifndef BOOST_ENUMS_MPL_LESS_HPP
+#define BOOST_ENUMS_MPL_LESS_HPP
+
+#include <boost/enums/mpl/enum_c_tag.hpp>
+#include <boost/mpl/integral_c.hpp>
+#include <boost/mpl/less.hpp>
+
+namespace boost {
+namespace mpl {
+
+template<>
+struct less_impl< enum_c_tag,enum_c_tag >
+{
+ template< typename R1, typename R2 > struct apply
+ : less<
+ integral_c<typename E1::underlying_type, (typename E1::underlying_type)(E1::value)>,
+ integral_c<typename E2::underlying_type, (typename E2::underlying_type)(E2::value)>
+ >
+ {
+ };
+};
+}
+}
+
+#endif // BOOST_ENUMS_MPL_LESS_HPP

Added: sandbox/enums/boost/enums/mpl/less_equal.hpp
==============================================================================
--- (empty file)
+++ sandbox/enums/boost/enums/mpl/less_equal.hpp 2011-03-04 19:34:21 EST (Fri, 04 Mar 2011)
@@ -0,0 +1,42 @@
+// less_equal.hpp
+//
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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.
+//
+// Adapted from libcxx tests
+//
+//////////////////////////////////////////////////////////////////////////////
+
+
+#ifndef BOOST_ENUMS_MPL_LESS_EQUAL_HPP
+#define BOOST_ENUMS_MPL_LESS_EQUAL_HPP
+
+#include <boost/enums/mpl/enum_c_tag.hpp>
+#include <boost/mpl/integral_c.hpp>
+#include <boost/mpl/less_equal.hpp>
+
+namespace boost {
+namespace mpl {
+
+template<>
+struct less_equal_impl< enum_c_tag,enum_c_tag >
+{
+ template< typename R1, typename R2 > struct apply
+ : less_equal<
+ integral_c<typename E1::underlying_type, (typename E1::underlying_type)(E1::value)>,
+ integral_c<typename E2::underlying_type, (typename E2::underlying_type)(E2::value)>
+ >
+ {
+ };
+};
+}
+}
+
+#endif // BOOST_ENUMS_MPL_LESS_EQUAL_HPP

Added: sandbox/enums/boost/enums/mpl/numeric_cast.hpp
==============================================================================
--- (empty file)
+++ sandbox/enums/boost/enums/mpl/numeric_cast.hpp 2011-03-04 19:34:21 EST (Fri, 04 Mar 2011)
@@ -0,0 +1,40 @@
+// numeric_cast.hpp
+//
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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.
+//
+// Adapted from libcxx tests
+//
+//////////////////////////////////////////////////////////////////////////////
+
+
+#ifndef BOOST_ENUMS_MPL_NUMERIC_CAST_HPP
+#define BOOST_ENUMS_MPL_NUMERIC_CAST_HPP
+
+#include <boost/enums/mpl/enum_c.hpp>
+#include <boost/mpl/integral_c.hpp>
+#include <boost/enums/mpl/enum_c_tag.hpp>
+#include <boost/mpl/numeric_cast.hpp>
+
+namespace boost {
+namespace mpl {
+
+template<> struct numeric_cast< integral_c_tag,enum_c_tag >
+{
+ template< typename N > struct apply
+ : integral_c< typename N::underlying_type, N::value >
+ {
+ };
+};
+
+}
+}
+
+#endif // BOOST_ENUMS_MPL_NUMERIC_CAST_HPP

Modified: sandbox/enums/boost/enums/pred.hpp
==============================================================================
--- sandbox/enums/boost/enums/pred.hpp (original)
+++ sandbox/enums/boost/enums/pred.hpp 2011-03-04 19:34:21 EST (Fri, 04 Mar 2011)
@@ -22,16 +22,16 @@
 namespace boost {
   namespace enums {
     namespace meta {
- template <typename EC>
- struct pred
+ template <typename EC, typename enum_type<EC>::type V>
+ struct pred
       {
- BOOST_STATIC_ASSERT(pos<EC>::value!=0);
- static const typename enum_type<EC>::type value =
- val<EC,pos<EC>::value-1>::value;
+ BOOST_STATIC_ASSERT((pos<EC,V>::value!=0));
+ BOOST_STATIC_CONSTEXPR typename enum_type<EC>::type value =
+ val<EC,pos<EC,V>::value-1>::value;
       };
     }
     template <typename EC>
- EC pred(EC e)
+ BOOST_CONSTEXPR EC pred(EC e)
     {
       BOOSt_ASSERT(pos(e)!=0);
       return val<EC>(pos(e)-1);

Modified: sandbox/enums/boost/enums/succ.hpp
==============================================================================
--- sandbox/enums/boost/enums/succ.hpp (original)
+++ sandbox/enums/boost/enums/succ.hpp 2011-03-04 19:34:21 EST (Fri, 04 Mar 2011)
@@ -22,16 +22,16 @@
 namespace boost {
   namespace enums {
     namespace meta {
- template <typename EC>
- struct succ
+ template <typename EC, typename enum_type<EC>::type V>
+ struct succ
       {
- BOOST_STATIC_ASSERT(pos<EC>::value!=(size<EC>::value-1));
- static const typename enum_type<EC>::type value =
- val<EC,pos<EC>+1>::value;
+ BOOST_STATIC_ASSERT((pos<EC,V>::value!=(size<EC>::value-1)));
+ static const typename enum_type<EC>::type value =
+ val<EC,pos<EC,V>::value+1>::value;
       };
     }
     template <typename EC>
- EC succ(EC e)
+ EC succ(EC e)
     {
       BOOSt_ASSERT(pos(e)!=(meta::size<EC>::value-1));
       return val<EC>(pos(e)+1);


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