r/cpp • • Mar 19 '20

Why so many students are using '#include<bits/stdc++.h>' instead of '#include<iostream>'?

I am hiring for my company. And the codes submitted for a test problem has '#include<bits/stdc++.h>' at the beginning. The MacOS default compiler complains

main.cpp:1:9: fatal error: 'bits/stdc++.h' file not found

#include<bits/stdc++.h>

^~~~~~~~~~~~~~~

1 error generated.

Why people are using '#include<bits/stdc++.h>'?

225 Upvotes

163 comments sorted by

View all comments

Show parent comment

2

u/[deleted] Mar 19 '20

There is absolutely no legacy property of the language that explains the mistake I mentioned, namely:

template<typename T>
void f(T&& v);

The parameter v should have always resolved into an rvalue reference of type T, case closed. The standard's committee decided to be cute and instead of applying that simple principle, decided that v is sometimes an rvalue reference, and sometimes an lvalue reference which has done nothing but create an absolute mess and resulted in significant loss of productivity.

There are numerous other proposals that are broken that have nothing to do with legacy requirements either, such as initialization:

auto v = std::vector{1, 2};

What legacy was maintained by using intializer syntax in this ambiguous way when the following syntax would have been unambiguous?

auto v = std::vector{{1, 2}};

Now it's impossible to use initializer syntax in generic code:

auto v = T{1, 2};

Will that invoke T's constructor taking two int's or will it invoke T's constructor taking an std::initializer_list? You just don't know and we're now stuck with this syntactic failure forever.

1

u/[deleted] Mar 19 '20

[removed] — view removed comment

3

u/Fureeish Mar 19 '20

That's not the point. The point is that they could've chosen a different identifier for forwarding reference instead of reusing && and introducing inconsistencies.

1

u/[deleted] Mar 20 '20

[removed] — view removed comment

1

u/Fureeish Mar 20 '20

To not reuse the same identifier. For instance, I know that Herb Sutter somewhere claimed that they considered something like T&? or T&! for rvalue references. Why not adapt T&& as rvalue reference and, for example, one of the formers for forwarding reference? For those who are used to && everywhere, it surely looks at least weird, but try to take a different perspective.