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,227 of 33,346   
   =?ISO-8859-1?Q?Daniel_Kr=FCgler?= to All   
   Re: stl clear and erase.   
   01 May 12 06:33:02   
   
   From: daniel.kruegler@googlemail.com   
      
   Am 01.05.2012 06:38, schrieb Chris Vine:   
   > On Mon, 30 Apr 2012 15:45:27 -0700 (PDT)   
   > Daniel Krügler  wrote:   
   > [snip]   
   >>> Isn't this similar to the problem of constructing a vector of int   
   >>> of a particular size, which in C++98 requires the constructor to   
   >>> be called for each of the vector's elements (so initializing them   
   >>> to 0), whether that is wanted or not?  I imagine C++11 requires   
   >>> the same.   
   >>   
   >> This is a very different thing. In contrast to the   
   >> pseudo-destructor the value-initializing constructor is *not* a   
   >> no-op. Any compiler can decide to omit the pseudo-destructor   
   >> evaluation, because this action is not observable, therefore I   
   >> consider your comparison as inappropriate.   
      
   In the last sentence I misleadingly referred to "any *compiler* can   
   decide to omit [..]", but actually I was thinking of an optimized   
   library implementation, so this should better say "Any library   
   implementation can decide to omit [..]".   
      
   > In theory, a compiler could deduce that the initial 0 value for a   
   > statically sized vector of int is never read in the program, and so   
   > elide the initialization, in the same way that it could elide the   
   > obviously no-op pseudo-destructor.  I agree that that would be   
   > harder for the compiler to deduce reliably though.   
      
   In theory, yes, but I haven't seen this happening in real life. It   
   would require a much more kind of non-local code analysis, while the   
   above mentioned pseudo-destructor elimination can easily be done by   
   means of portable library code. The usual technique is to evaluate   
   some trait, like is_trivially_destructible (or corresponding compiler   
   intrinsics that did already exist in C++03) and to make a compile-time   
   code branch here. There is no much magic involved and therefore this   
   technique is very popular.   
      
   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