home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 33,229 of 33,346   
   Seungbeom Kim to All   
   Re: max enum value +1   
   05 Oct 13 04:40:27   
   
   From: musiphil@bawi.org   
      
   On 2013-10-03 23:59, fmatthew5876 wrote:   
   >   
   > It would be great if there was just some way to get the max count +1 of   
   > any enum.   
   > Something like:   
   >   
   > enum Color {   
   > kRed,   
   > kBlue,   
   > kGreen   
   > };   
   > constexpr int kNumColors = std:enum_bound(Color);   
      
   The syntax has to be different unless enum_bound becomes a keyword,   
   because Color is a type.   
      
   It would be great if the compiler generates something like this   
   automatically:   
      
   namespace std {   
      
   template    
   struct enum_traits;   
      
   // for the Color type as defined above:   
   template <>   
   struct enum_traits {   
        typedef implementation-specified underlying_type;   
        static const Color decl_min = kRed;         // e_min   
        static const Color decl_max = kGreen;       // e_max   
        static const Color valid_min = Color(0);    // b_min   
        static const Color valid_max = Color(3);    // b_max   
   };   
      
   }   
      
   Hasn't there been any proposal like this before?   
      
   I think we need inclusive max values instead of the 'max+1' values,   
   because the latter may not be in the valid range for the underlying   
   type (e.g. enum class E : unsigned char { min=0, max=255 };).   
      
   --   
   Seungbeom Kim   
      
      
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca