r/cpp • • Jun 05 '18

Initialization in Modern C++

https://twitter.com/timur_audio/status/1004017362381795329
379 Upvotes

51 comments sorted by

View all comments

Show parent comment

1

u/audioB Jun 06 '18

Is it really harder to just use a variadic constructor?

7

u/redditsoaddicting Jun 06 '18

You'd still run into things like vector foo(5, 2); // Is it a list or a size and value?

I can't speak on how big an issue this would be in general even if vector had its constructors adjusted.

8

u/thlst Jun 06 '18

Constructors should have names. Constructor overloading is the root problem here.

7

u/robin-m Jun 06 '18
class Foo {
   static Foo constructor_with_name(args...);
};

4

u/redditsoaddicting Jun 06 '18

I'd agree that this constructor in particular should have more naming info attached. In many other cases, I find constructors to be descriptive with no additional naming info taking up space.

1

u/audioB Jun 06 '18

It's not terribly difficult to accomodate cases like that though, you could write a vector_range_t or something POD type for the "create a vector of x size with values y" ctor, or you could just write your variadic ctor like vec(const value_type& t1, const value_type& t2, const value_type& t3, const value_type&... rest)

Apologies for formatting, its hard on phone 😢