Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r69490 - sandbox/enums/boost/enums
From: vicente.botet_at_[hidden]
Date: 2011-03-02 17:00:21


Author: viboes
Date: 2011-03-02 17:00:18 EST (Wed, 02 Mar 2011)
New Revision: 69490
URL: http://svn.boost.org/trac/boost/changeset/69490

Log:
Enums: Clanup + FIx CONSTEXPR warning (which hides an error)
Text files modified:
   sandbox/enums/boost/enums/enum_array.hpp | 53 +++++++++++++++++++++++----------------
   sandbox/enums/boost/enums/enum_traiter.hpp | 22 ++++++++--------
   sandbox/enums/boost/enums/get_value.hpp | 7 ++---
   sandbox/enums/boost/enums/size.hpp | 3 --
   sandbox/enums/boost/enums/val.hpp | 2
   5 files changed, 46 insertions(+), 41 deletions(-)

Modified: sandbox/enums/boost/enums/enum_array.hpp
==============================================================================
--- sandbox/enums/boost/enums/enum_array.hpp (original)
+++ sandbox/enums/boost/enums/enum_array.hpp 2011-03-02 17:00:18 EST (Wed, 02 Mar 2011)
@@ -39,7 +39,7 @@
 //#include <boost/tuples.hpp>
 #include <boost/type_traits/integral_constant.hpp>
 
-// FIXES for broken compilers
+// FIXES for broken compilers + CONSTEXPR
 #include <boost/config.hpp>
 
 
@@ -49,7 +49,7 @@
     template<class T, typename EC>
     class enum_array {
       public:
- T elems[enums::meta::size<EC>::value]; // fixed-size array of elements of type T
+ T elems[meta::size<EC>::value]; // fixed-size array of elements of type T
         
       public:
         // type definitions
@@ -63,7 +63,7 @@
         typedef EC key_type;
         typedef std::size_t size_type;
         typedef std::ptrdiff_t difference_type;
- static const std::size_t N = enums::meta::size<EC>::value;
+ static const std::size_t N = meta::size<EC>::value;
 
         // iterator support
         iterator begin() { return elems; }
@@ -114,14 +114,14 @@
         // operator[]
         reference operator[](key_type k)
         {
- size_type i = enums::pos(k);
+ size_type i = pos(k);
             BOOST_ASSERT( i < N && "out of range" );
             return elems[i];
         }
         
         const_reference operator[](key_type k) const
         {
- size_type i = enums::pos(k);
+ size_type i = pos(k);
             BOOST_ASSERT( i < N && "out of range" );
             return elems[i];
         }
@@ -160,9 +160,18 @@
         }
 
         // size is constant
- BOOST_STATIC_CONSTEXPR size_type size() { return N; }
- static bool empty() { return false; }
- BOOST_STATIC_CONSTEXPR size_type max_size() { return N; }
+ BOOST_CONSTEXPR size_type size()
+ {
+ return N;
+ }
+ static bool empty()
+ {
+ return false;
+ }
+ BOOST_CONSTEXPR size_type max_size()
+ {
+ return N;
+ }
         enum { static_size = N };
 
         // swap (note: linear complexity)
@@ -195,7 +204,7 @@
         // check range (may be private because it is static)
         static size_type rangecheck (key_type k) {
         size_type i = rangecheck(k);
- if (i >= size()) {
+ if (i >= N) {
                 std::out_of_range e("array<>: index out of range");
                 boost::throw_exception(e);
             }
@@ -253,28 +262,28 @@
     
    // Specific for boost::enums::enum_array: simply returns its elems data member.
    template <typename T, typename EC>
- typename detail::c_array<T,N>::type& get_c_array(boost::enums::enum_array<T,EC>& arg)
+ typename detail::c_array<T,N>::type& get_c_array(enum_array<T,EC>& arg)
    {
        return arg.elems;
    }
 
    // Specific for boost::enums::enum_array: simply returns its elems data member.
    template <typename T, typename EC>
- typename const detail::c_array<T,N>::type& get_c_array(const boost::enums::enum_array<T,EC>& arg)
+ typename const detail::c_array<T,N>::type& get_c_array(const enum_array<T,EC>& arg)
    {
        return arg.elems;
    }
 #else
 // Specific for boost::enums::enum_array: simply returns its elems data member.
     template <typename T, typename EC>
- T(&get_c_array(boost::enums::enum_array<T,EC>& arg))[enums::meta::size<EC>::value]
+ T(&get_c_array(enum_array<T,EC>& arg))[meta::size<EC>::value]
     {
         return arg.elems;
     }
     
     // Const version.
     template <typename T, typename EC>
- const T(&get_c_array(const boost::enums::enum_array<T,EC>& arg))[enums::meta::size<EC>::value]
+ const T(&get_c_array(const enum_array<T,EC>& arg))[meta::size<EC>::value]
     {
         return arg.elems;
     }
@@ -284,27 +293,27 @@
     
     template <class T, typename EC>
     class tuple_size<enum_array<T, EC> >
- : public integral_constant<size_t, enums::meta::size<EC>::value> {};
+ : public integral_constant<size_t, meta::size<EC>::value> {};
 
     template <class T, typename EC>
     class tuple_size<const enum_array<T, EC> >
- : public integral_constant<size_t, enums::meta::size<EC>::value> {};
+ : public integral_constant<size_t, meta::size<EC>::value> {};
 
- template <class T, typename EC, enums::enum_type<EC>::type K>
+ template <class T, typename EC, enum_type<EC>::type K>
     class tuple_element<enum_array<T, EC> >
     {
     public:
         typedef T type;
     };
 
- template <class T, typename EC, enums::enum_type<EC>::type K>
+ template <class T, typename EC, enum_type<EC>::type K>
     class tuple_element<const enum_array<T, EC> >
     {
     public:
         typedef const T type;
     };
 
- template <class T, typename EC, enums::enum_type<EC>::type K>
+ template <class T, typename EC, enum_type<EC>::type K>
      inline
     T&
     get(enum_array<T, EC>& a)
@@ -312,8 +321,8 @@
         return a[K];
     }
 
- template <class T, typename EC, enums::enum_type<EC>::type K>
- _LIBCPP_INLINE_VISIBILITY inline
+ template <class T, typename EC, enum_type<EC>::type K>
+ inline
     const T&
     get(const enum_array<T, EC>& a)
     {
@@ -322,9 +331,9 @@
 
     #ifndef BOOST_NO_RVALUE_REFERENCES
 
- template <class T, typename EC, enums::enum_type<EC>::type K>
+ template <class T, typename EC, enum_type<EC>::type K>
     T&&
- get(array<T, enums::meta::size<EC>::value>&& a)
+ get(array<T, meta::size<EC>::value>&& a)
     {
         return boost::move(a[K]);
     }

Modified: sandbox/enums/boost/enums/enum_traiter.hpp
==============================================================================
--- sandbox/enums/boost/enums/enum_traiter.hpp (original)
+++ sandbox/enums/boost/enums/enum_traiter.hpp 2011-03-02 17:00:18 EST (Wed, 02 Mar 2011)
@@ -24,23 +24,23 @@
 namespace boost {
   namespace enums {
     template <typename EC,
- int Last=enums::meta::size<EC>::value-1,
- int First=0
+ std::size_t Last=meta::size<EC>::value-1,
+ std::size_t First=0
>
     struct enum_traiter
     {
       typedef EC enum_type;
- static const int first_index = First;
- static const int last_index = Last;
- static const int size = Last-First+1;
+ static const std::size_t first_index = First;
+ static const std::size_t last_index = Last;
+ static const std::size_t size = Last-First+1;
 
       static EC first()
       {
- return boost::convert_to<EC>(enums::meta::val<EC,First>::value);
+ return boost::convert_to<EC>(meta::val<EC,First>::value);
       }
       static EC last()
       {
- return boost::convert_to<EC>(enums::meta::val<EC,Last>::value);
+ return boost::convert_to<EC>(meta::val<EC,Last>::value);
       }
       
     };
@@ -48,13 +48,13 @@
     struct linear_enum_traiter : enum_traiter<EC>
     {
     typedef enum_traiter<EC> base_type;
- static int pos(EC e)
+ static std::size_t pos(EC e)
       {
- return (enums::get_value(e)-base_type::first_index);
+ return (get_value(e)-base_type::first_index);
       }
- static EC val(int i)
+ static EC val(std::size_t i)
       {
- typename enums::underlying_type<EC>::type ut = i+base_type::first_index;
+ typename underlying_type<EC>::type ut = i+base_type::first_index;
         return boost::convert_to<EC>(ut);
       }
     };

Modified: sandbox/enums/boost/enums/get_value.hpp
==============================================================================
--- sandbox/enums/boost/enums/get_value.hpp (original)
+++ sandbox/enums/boost/enums/get_value.hpp 2011-03-02 17:00:18 EST (Wed, 02 Mar 2011)
@@ -15,7 +15,7 @@
 
 #include <boost/config.hpp>
 #include <boost/enums/enum_type.hpp>
-#include <iostream>
+
 namespace boost {
   namespace enums {
 
@@ -25,10 +25,9 @@
     get_value(EC e)
     {
 #ifdef BOOST_NO_SCOPED_ENUMS
- std::cout << __LINE__ << std::endl;
- return e.get();
+ return e.get();
 #else
- std::cout << __LINE__ << std::endl; return e;
+ return e;
 #endif
     }
   }

Modified: sandbox/enums/boost/enums/size.hpp
==============================================================================
--- sandbox/enums/boost/enums/size.hpp (original)
+++ sandbox/enums/boost/enums/size.hpp 2011-03-02 17:00:18 EST (Wed, 02 Mar 2011)
@@ -22,9 +22,6 @@
       template <typename EC>
       struct size;
     }
- //{
- // typename int value = ...;
- //};
 
   }
 }

Modified: sandbox/enums/boost/enums/val.hpp
==============================================================================
--- sandbox/enums/boost/enums/val.hpp (original)
+++ sandbox/enums/boost/enums/val.hpp 2011-03-02 17:00:18 EST (Wed, 02 Mar 2011)
@@ -22,7 +22,7 @@
       struct val;
     }
     template <typename EC>
- EC val(int p)
+ EC val(std::size_t p)
     {
       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