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 32,234 of 33,346   
   =?ISO-8859-1?Q?Daniel_Kr=FCgler?= to All   
   Re: Why no conversion from std::initiali   
   02 May 12 23:08:06   
   
   From: daniel.kruegler@googlemail.com   
      
   Am 02.05.2012 21:12, schrieb Ivan Godard:   
   > I see that there needs to be a constexpr size() for initializer lists,   
   > and actually I'd thought that there was one - perhaps this should be   
   > added independently of my proposal, because I can see other places in   
   > which it might be useful.   
      
   Yes, certainly.   
      
   > However, I don't understand why "ls" has to be constexpr in your example   
   > (or rather, why ars needs a constexpr initializer). Yes, the compiler   
   > needs to save the values on the list at run time rather than than at   
   > compile time, but it does that anyway. And surely the compiler can   
   > subscript the ls list (even though the programmer cannot) to get the   
   > values to use to initialize the ars elements with. I'm ignorant here -   
   > why constexpr?   
      
   This is a definition problem: What you are intending (quite reasonably) is a   
   partial constant expression: The size needs to be a constant expression, but   
   not necessarily the contents of the referenced array. How to specify the state   
   of this? I'm not    
   saying that this would be impossible, but it requires some special wording to   
   make that possible. The good news are that this wording needs only be applied   
   to std::initializer_list (which is a "magic" type anyway), but I still   
   consider this as    
   problematic. Note that there are currently no restrictions of st   
   ::initializer_list objects compared to other objects. This means, you can   
   legally declare a variable without initializing it with data, like so:   
      
   std::initializer_list li; // E.g. at local scope   
      
   and at some other place you can assign a new value to it. These are   
   situations, where obviously the li object cannot have an effective constant   
   expression when li.size() is evaluated. Currently we have a uniform way to   
   ensure that a variable can be used    
   as part of constant expressions, this is a declaration of a constexpr   
   variable. Of-course some other expressions can also be used as a constant   
   expression, e.g. a variable with static storage duration can be used to define   
   an address-constant or    
   reference-constant expression but does not require a constexpr specifier. But   
   this holds only for "identity-aware" constant expressions at the moment. There   
   does not exist yet a similar concept for constant "values". But the result of   
   li.size() is such a    
   "value". Either we must invent a syntactic construction (similar to a   
   constexpr specifier) that allows to mark an initializer as a constant value,   
   but not necessarily in all aspects, or we must precisely define the conditions   
   under whi   
    ch the expression li.size() shall be considered as constant expression, *even   
   though* the complete object li itself may not be declared as a constant   
   expression. I hope that we can realize the latter at some point in time, but   
   it is not a trivial thing    
   and needs careful drafting.   
      
   HTH & Greetings from Bremen,   
      
   Daniel Krügler   
      
      
      
      
   --   
         [ 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