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,862 of 33,346   
   Seungbeom Kim to All   
   Re: Surprising behaviour of c++11 vector   
   15 Feb 13 22:15:18   
   
   -september.org> 32629b2f   
   From: musiphil@bawi.org   
      
   On 2013-02-10 09:06, Tobias Müller wrote:   
   > Seungbeom Kim  wrote:   
   >> I'm afraid I don't see what's going on here.   
   >   
   > The range constructor probably looks like:   
   >   
   > template    
   > template    
   > std::vector::vector(It begin, It end)   
   > {   
   >    for (It it = begin; it != end; ++it)   
   >    {   
   >       Alloc::construct(internalBufferPointer, *it);   
   >       internalBufferPointer += sizeof A;   
   >    }   
   > }   
      
   std::vector should have a constructor taking a pair of iterators   
   (plus an allocator with a default value), but is it relevant here?   
   I was talking about a constructor that takes an std::initializer_list,   
   which I should have referred to as "an initializer-list constructor"   
   (8.5.4/2).   
      
   >   
   >> Why does the range constructor for v1 produce fatal behavior at   
   >> run-time,   
   >   
   > for (const char* it = "abc"; it != "def"; ++it)   
   > {/.../}   
      
   v1 expects an std::initializer_list, which gives iterators of type   
   'const A*', while the given initializer looks like an std::initializer_   
   list, with iterators of type 'const char**'. From my   
   understanding of 8.5.4, I expect that the initializer should be treated   
   like { A("abc"), A("def") }, as an std::initializer_list, but in no   
   case do I expect an iterator of type 'const char*' will be used.   
      
   >   
   >> and why does it not when A::A(char const *) is explicit?   
   >   
   > In C++03:   
   > void construct ( pointer p, const_reference val );   
      
   I assume you're refererring to that in std::allocator.   
   What is T here, and what difference does this function make?   
      
   >   
   >> And why does the initialization of v2 fail to compile?   
      
   Doesn't this use the same std::initializer_list as above?   
   I'm still waiting for an explanation.   
      
   Thank you.   
      
   --   
   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