790d265a   
   From: schaub.johannes@googlemail.com   
      
   Am 11.05.2012 12:39, schrieb Nikolay Ivchenkov:   
   > On 11 May, 01:30, Daniel Krügler   
   > wrote:   
   >> Am 10.05.2012 20:48, schrieb Nikolay Ivchenkov:   
   >>> struct X   
   >>> {   
   >>> ~X() {}   
   >>> };   
   >>   
   >> ....   
   >>   
      
   > On 11 May, 03:18, Johannes Schaub   
   > wrote:   
   >>   
   >> Issue 1116 tries to solve this, so that in your code, also the   
   >> first "destroy" is undefined behavior because you have not yet   
   >> copied another T object into "*p".   
   >   
   > AFAICS, the proposed resolution of issue 1116 is not relevant   
   > here. A trivially copyable class cannot have non-trivial destructor.   
   >   
      
   I'm sorry. I wasn't aware that the destructor needs to be trivial for   
   a class to be trivially copyable.   
      
   I think it is strange that neither the first bullet of 1116 nor the   
   second bullet appears to match for your case.   
      
   >> You can create one by writing into a data member of "X" or by doing   
   >> a "placement-new" of X into that location.   
   > I don't want to do such things. I'm implementing my own Vector, it   
   > is able to create default-initialized elements:   
   >   
   > // creates n default-initialized objects of type X   
   > Vector v(n, DefaultInitialize());   
   >   
   > I want to optimize creation of sequence of objects with trivial   
   > initialization: the complexity of such operation should be constant   
   > (finite sequence of no-ops = no-op) if this is possible within the   
   > current C++ object model.   
      
   An object with trivial initialization (like "int" or "X") is not   
   automatically created just because you have memory and suitable   
   alignment. But since you provide a value initialized source value and   
   presumably have to initialize the memory with that value using   
   placement new anyway, that would look considerably different from your   
   testcase that you showed.   
      
   What am I missing here?   
      
      
   --   
    [ 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)   
|