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,865 of 33,346   
   =?ISO-8859-1?Q?=D6=F6_Tiib?= to mk.ivc...@googlemail.com   
   Re: Surprising behaviour of c++11 vector   
   20 Feb 13 12:02:45   
   
   From: ootiib@hot.ee   
      
   On Wednesday, 20 February 2013 18:48:58 UTC+2,   
   mk.ivc...@googlemail.com wrote:   
   > On Thursday, February 7, 2013 2:48:36 AM UTC+4, Andy Venikov wrote:   
   > > I came across a class, that could be boiled-down to this:   
   > >   
   > > class A   
   > > {   
   > >    std::string str_;   
   > >   
   > > public:   
   > >    explicit A(char const * str) : str_(str) {}   
   > >    explicit A(char ch) : str_(ch) {}   
   > > };   
   > >   
   > > Trying to initialize a vector of this class, I unthinkingly   
   > > coded the following:   
   > >   
   > > vector v1 { "abc", "def" };   
   > >   
   > > It compiled.   
   >   
   > I consider that as just another evidence that uniform initialization   
   > is silly.   
   > It looks similar to (if not worse than) C-style cast which may   
   > "uniformly" perform entirely different type conversions.   
   >   
   > > Any thought on whether this should be fixed?   
   >   
   > IMO, it would be nice to have more accurate initialization model,   
   > list-initialization with a non-empty braced-init-list should be   
   > deprecated.   
      
   Possibly it is cooperative effect of several bad things.   
      
   0) a char pointer/array/literal is *way* too loose thing from all   
       ends.   
   1) std::string is also loose. 'false' converts at no noise level into   
       'std::string const&' on all compilers that I can reach.   
   2) vector has slightly too lot of constructors. 9 I think. Several   
       have default arguments and at least one is a template of   
       constructor.   
   3) the differences between those constructors are slightly too small.   
   4) the language manages to be slightly too smart when resolving   
       ambiguities.   
   5) the new rules of initialization are slightly too loose.   
      
   I have a feeling that the compilers also do (have to) chain implicit   
   conversions in such circumstances. Sure, some language lawyer can   
   point out why ... but for me it feels too type-unsafe.   
      
      
   --   
         [ 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