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,225 of 33,346    |
|    Francis Glassborow to All    |
|    Re: max enum value +1    |
|    04 Oct 13 09:55:03    |
   
   From: francis.glassborow@btinternet.com   
      
   On 04/10/2013 07: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);   
   >   
   >   
      
   What about:   
      
   enum Color { // How I hate spellings that are specific to   
    // to one side of the Atlantic   
    red, blue, green, count };   
   constexpr unsigned colors{(unsigned) count};   
      
   Though I would prefer to use a scoped enum for this, saves risk of   
   name-clashes. Yes, count is not a color but presumably you are going to   
   check count in the context.   
      
   Francis   
      
      
   --   
    [ 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