Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r69522 - sandbox/enums/boost/enums
From: vicente.botet_at_[hidden]
Date: 2011-03-03 13:04:46


Author: viboes
Date: 2011-03-03 13:04:45 EST (Thu, 03 Mar 2011)
New Revision: 69522
URL: http://svn.boost.org/trac/boost/changeset/69522

Log:
Enums: complte Ada like functions and make use of std::size_t for position
Added:
   sandbox/enums/boost/enums/pred.hpp (contents, props changed)
   sandbox/enums/boost/enums/succ.hpp (contents, props changed)
Text files modified:
   sandbox/enums/boost/enums/enum_set.hpp | 2 +-
   sandbox/enums/boost/enums/first.hpp | 5 +++++
   sandbox/enums/boost/enums/include.hpp | 4 ++++
   sandbox/enums/boost/enums/last.hpp | 7 ++++++-
   sandbox/enums/boost/enums/pos.hpp | 3 ++-
   sandbox/enums/boost/enums/size.hpp | 5 +++++
   sandbox/enums/boost/enums/val.hpp | 6 +++++-
   7 files changed, 28 insertions(+), 4 deletions(-)

Modified: sandbox/enums/boost/enums/enum_set.hpp
==============================================================================
--- sandbox/enums/boost/enums/enum_set.hpp (original)
+++ sandbox/enums/boost/enums/enum_set.hpp 2011-03-03 13:04:45 EST (Thu, 03 Mar 2011)
@@ -181,7 +181,7 @@
       
     public:
       
- std::bitset<traits::size> detail_bits() { return bits; }
+ std::bitset<traits::size+1> detail_bits() { return bits; }
     };
 
     // enum_set operators:

Modified: sandbox/enums/boost/enums/first.hpp
==============================================================================
--- sandbox/enums/boost/enums/first.hpp (original)
+++ sandbox/enums/boost/enums/first.hpp 2011-03-03 13:04:45 EST (Thu, 03 Mar 2011)
@@ -25,6 +25,11 @@
         static const typename enum_type<EC>::type value = enums::meta::val<EC,0>::value;
       };
     }
+ template <typename EC>
+ EC first()
+ {
+ return meta::val<EC,0>::value;
+ }
   }
 }
 

Modified: sandbox/enums/boost/enums/include.hpp
==============================================================================
--- sandbox/enums/boost/enums/include.hpp (original)
+++ sandbox/enums/boost/enums/include.hpp 2011-03-03 13:04:45 EST (Thu, 03 Mar 2011)
@@ -15,7 +15,9 @@
 
 #include <boost/enums/default_value.hpp>
 #include <boost/enums/emulation.hpp>
+#include <boost/enums/enum_array.hpp>
 #include <boost/enums/enum_range.hpp>
+#include <boost/enums/enum_set.hpp>
 #include <boost/enums/enum_traiter.hpp>
 #include <boost/enums/enum_traits.hpp>
 #include <boost/enums/enum_type.hpp>
@@ -23,7 +25,9 @@
 #include <boost/enums/first.hpp>
 #include <boost/enums/last.hpp>
 #include <boost/enums/pos.hpp>
+#include <boost/enums/pred.hpp>
 #include <boost/enums/size.hpp>
+#include <boost/enums/succ.hpp>
 #include <boost/enums/underlying_type.hpp>
 #include <boost/enums/val.hpp>
 

Modified: sandbox/enums/boost/enums/last.hpp
==============================================================================
--- sandbox/enums/boost/enums/last.hpp (original)
+++ sandbox/enums/boost/enums/last.hpp 2011-03-03 13:04:45 EST (Thu, 03 Mar 2011)
@@ -23,9 +23,14 @@
       template <typename EC>
       struct last
       {
- static const typename enum_type<EC>::type value = enums::meta::val<EC,enums::meta::size<EC>::value-1>::value;
+ static const typename enum_type<EC>::type value = val<EC,size<EC>::value-1>::value;
       };
     }
+ template <typename EC>
+ EC last()
+ {
+ return meta::val<EC,meta::size<EC>::value-1>::value;
+ }
   }
 }
 

Modified: sandbox/enums/boost/enums/pos.hpp
==============================================================================
--- sandbox/enums/boost/enums/pos.hpp (original)
+++ sandbox/enums/boost/enums/pos.hpp 2011-03-03 13:04:45 EST (Thu, 03 Mar 2011)
@@ -15,6 +15,7 @@
 
 #include <boost/enums/enum_type.hpp>
 #include <boost/enums/enum_traits.hpp>
+#include <cstddef>
 
 
 namespace boost {
@@ -24,7 +25,7 @@
       struct pos;
     }
     template <typename EC>
- int pos(EC e)
+ std::size_t pos(EC e)
     {
       return enum_traits<EC>::pos(e);
     }

Added: sandbox/enums/boost/enums/pred.hpp
==============================================================================
--- (empty file)
+++ sandbox/enums/boost/enums/pred.hpp 2011-03-03 13:04:45 EST (Thu, 03 Mar 2011)
@@ -0,0 +1,42 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_PRED_HPP
+#define BOOST_ENUMS_PRED_HPP
+
+#include <boost/enums/enum_type.hpp>
+#include <boost/enums/pos.hpp>
+#include <boost/enums/val.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/assert.hpp>
+
+namespace boost {
+ namespace enums {
+ namespace meta {
+ template <typename EC>
+ struct pred
+ {
+ BOOST_STATIC_ASSERT(pos<EC>::value!=0);
+ static const typename enum_type<EC>::type value =
+ val<EC,pos<EC>::value-1>::value;
+ };
+ }
+ template <typename EC>
+ EC pred(EC e)
+ {
+ BOOSt_ASSERT(pos(e)!=0);
+ return val<EC>(pos(e)-1);
+ }
+ }
+}
+
+#endif

Modified: sandbox/enums/boost/enums/size.hpp
==============================================================================
--- sandbox/enums/boost/enums/size.hpp (original)
+++ sandbox/enums/boost/enums/size.hpp 2011-03-03 13:04:45 EST (Thu, 03 Mar 2011)
@@ -22,6 +22,11 @@
       template <typename EC>
       struct size;
     }
+ template <typename EC>
+ std::size_t size()
+ {
+ return meta::size<EC>();
+ }
 
   }
 }

Added: sandbox/enums/boost/enums/succ.hpp
==============================================================================
--- (empty file)
+++ sandbox/enums/boost/enums/succ.hpp 2011-03-03 13:04:45 EST (Thu, 03 Mar 2011)
@@ -0,0 +1,42 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_SUCC_HPP
+#define BOOST_ENUMS_SUCC_HPP
+
+#include <boost/enums/enum_type.hpp>
+#include <boost/enums/pos.hpp>
+#include <boost/enums/val.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/assert.hpp>
+
+namespace boost {
+ namespace enums {
+ namespace meta {
+ template <typename EC>
+ 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;
+ };
+ }
+ template <typename EC>
+ EC succ(EC e)
+ {
+ BOOSt_ASSERT(pos(e)!=(meta::size<EC>::value-1));
+ return val<EC>(pos(e)+1);
+ }
+ }
+}
+
+#endif

Modified: sandbox/enums/boost/enums/val.hpp
==============================================================================
--- sandbox/enums/boost/enums/val.hpp (original)
+++ sandbox/enums/boost/enums/val.hpp 2011-03-03 13:04:45 EST (Thu, 03 Mar 2011)
@@ -14,16 +14,20 @@
 #define BOOST_ENUMS_VALUE_HPP
 
 #include <boost/enums/enum_traits.hpp>
+#include <boost/enums/size.hpp>
+#include <boost/assert.hpp>
+#include <cstddef>
 
 namespace boost {
   namespace enums {
     namespace meta {
- template <typename EC, int I>
+ template <typename EC, std::size_t I>
       struct val;
     }
     template <typename EC>
     EC val(std::size_t p)
     {
+ BOOST_ASSERT(p<(meta::size<EC>::value));
       return enum_traits<EC>::val(p);
     }
 


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