lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] Switch to using C++11 uniform initialization in the ctor initi


From: Vadim Zeitlin
Subject: Re: [lmi] Switch to using C++11 uniform initialization in the ctor initializer lists?
Date: Fri, 24 Aug 2018 15:08:39 +0200

On Fri, 24 Aug 2018 02:03:10 +0000 Greg Chicares <address@hidden> wrote:

GC> On 2018-08-23 23:24, Vadim Zeitlin wrote:
[... avoiding vector ctor taking initializer_list ...]
GC> > so the only alternative I see is to have a function like
GC> > this:
GC> > 
GC> >   template <typename T>
GC> >   std::vector<T>
GC> >   make_vector_of_size(std::size_t size, T value = T{})
GC> >   {
GC> >       return std::vector(size, value);
GC> >   }
[...]
GC> > but the more I think it, more I actually like this
GC> > idea as it's just much more readable than a raw ctor call.
GC> 
GC> No, really? It seems weird to introduce an auxiliary function just to
GC> initialize a standard container. If we were taking maintainership of
GC> an orphaned C++ library (as you and Vaclav did for xmlwrapp) and it
GC> had such a thing, wouldn't we consider removing in order to render
GC> the code comprehensible?

 Sure, and if I were writing std::vector I would have never given it an
(size_t, T) ctor overload in the first place, as there are much better (as
in more readable and less error-prone, even before C++11 introduction of
initializer_list) ways to do it. But the problem is so bad precisely
because we can't touch std::vector in any way. And this is why using a
helper function is required.

GC> You might say that this is like std::make_pair<>(), but my impression
GC> is that there's no need for that anymore

 No, I don't think it's ever needed in C++17.

GC> > GC> One idea is not to modernize container construction. I'm guessing
GC> > GC> that 'ContainerType z(anything)' will rarely if ever be compatible
GC> > GC> with '{}' in the lmi corpus.
GC> > 
GC> >  AFAICS, even never. I guess I can live with an inconsistency between
GC> > containers and everything else, but maybe it's worth introducing
GC> > make_container_of_size() to avoid it?
GC> 
GC> I'd better sleep on it and take a fresh look on a different day,
GC> but I suspect that container initializers with '()' will stand out
GC> so clearly against an otherwise-uniform '{}' background as to be
GC> immediately clear.

 I thought so too, but it's still just a one (well, 2) character difference
and from this point of view make_container_of_size() would stand out much
more.

 Honestly, I just hate this vector so much that I'd be glad to never use
it again. Just try to guess what does this do if you see it for the first
time:

    :allowed_(cardinality_of_the_enumeration, true)

 Using make_container_of_size() would be really much nicer in this, and
plenty of other, cases IMO.

VZ


reply via email to

[Prev in Thread] Current Thread [Next in Thread]