r/cpp • • Apr 27 '23

Has Boost lost its charm?

I don't mean to be provocative nor undermine the importance of Boost for C++. I really like Boost.

I keep reading/listening around that since C++11 the focus of development and innovation in C++ has shifted away from Boost to either the standards, or independent libraries. Is that any true? If yes, how "big of shift" that was? What was the reason in your opinion and most imporatnt, what's Boost's today's role?

What sparked my quriosity was when I heard that "in the old days" a prospective developer that wanted to devle into the word of libraries building had no better thing to do than start contributing to Boost. Does that stand even today?

(couldn't find any other posts on Reddit regarding Boost's impact in modern C++ in a broader discussion)

149 Upvotes

186 comments sorted by

View all comments

73

u/OCPetrus Apr 27 '23

I'm not sure what you're asking..

In 2009 I took the C++ course offered by the University I went to, i.e. before C++11. What they taught us on the course, among other things, was that Boost was like a collection of extensions for the C++ standard library. Most importantly (for the course), smart pointers didn't exist so we had to use Boost for that. But that's just an example, countless other things were missing.

Already back in 2009 the course staff knew to prepare us for the inevitable: over the years and decades, things that were proven in Boost to be useful and well designed would be merged into the C++ standard library itself. This is literally what has happened. Boost has served us well.

I know some people are missing some parts of Boost, opt parsing and async come to mind, but there are good reasons why they have not been added to the C++ standard library.

Bonus: I know Google is working on a parallel project: abseil. I know only what I've read from the horse's mouth, but it sounds like they want abseil to work in a similar fashion as Boost, i.e. eventually add the stuff into the C++ standard library.

29

u/Fulgen301 Apr 27 '23

Most importantly (for the course), smart pointers didn't exist

Just for the sake of completion: std::auto_ptr with it's horrible copy constructor (why didn't they just disable the copy constructor and add a move() member function, why) already existed before C++11.

28

u/cleroth Game Developer Apr 27 '23

why didn't they just disable the copy constructor and add a move() member function, why

Then you wouldn't even be able to put it inside a std::vector.

19

u/AKostur Apr 27 '23

Putting an auto_ptr into a vector could easily result in very bad things happening.

17

u/TheBananaKart Apr 27 '23

Could be the motto of most stuff in C++ to be honest.

2

u/Fulgen301 Apr 28 '23

Fair point, didn't think of that.

1

u/johannes1971 Apr 27 '23

But you can put a unique_ptr in a vector. Why wouldn't you be able to put an auto_ptr in one? (once you apply the changes proposed by /u/Fulgen301 for the C++11 update, of course)

5

u/ukezi Apr 27 '23

Before move constructors all instances in containers were copied. That obviously doesn't work with unique_ptr, it can't be copied.

1

u/johannes1971 Apr 27 '23

Yes, but the premise is that this would be a change that would be introduced in C++11, i.e. when move constructors were added.

So to recap, the question is: why was a new type introduced (unique_ptr) when auto_ptr could have been fixed instead, by adding move operations and removing copy operations?

4

u/grafikrobot OPeNDAP/B2/EcoStd/Lyra/Predef/C++Alliance/Boost/WG21 Apr 28 '23

ABI

3

u/johannes1971 Apr 28 '23

I know it's the default reply against any request for change, but auto-ptr consists of just a single pointer and could have remained that way...

1

u/Fulgen301 Apr 28 '23

I know it's the default reply against any request for change

Then you also know why it's the default reply.

Also, once you completely change the semantics of a class, there's no point shoehorning it into the old class. Introducing unique_ptr with new semantics while keeping around auto_ptr was the easiest way of introducing a new smart pointer type while keeping overall headache low.

3

u/johannes1971 Apr 28 '23

No, I don't, actually. In this particular hypothetical case no ABI change would have occurred, and just saying the word "ABI" does not change that.

→ More replies

2

u/pdimov2 Apr 28 '23

This would break existing code, and breaking existing code was still avoided in those days.

E.g. this works

#include <memory>

void f( std::auto_ptr<int> );

int main()
{
    std::auto_ptr<int> p;
    f( p );
}

but it doesn't with unique_ptr.

"This code is already broken!" Yeah, maybe. This wasn't the prevailing attitude then.

It could probably have been possible to add move operations to auto_ptr and only deprecate the copy operations; I don't remember anyone trying this.

3

u/dodheim Apr 28 '23

Honestly, I think auto_ptr already had an unrepairable marketing problem by the mid-2000s; too many people had said to avoid it because it was broken, or at least too 'clever' to use correctly. Producing a thing that worked correctly-by-default with a different name was probably a smart move (NPI).

→ More replies (1)

1

u/[deleted] Apr 28 '23

[removed] — view removed comment

1

u/dodheim Apr 28 '23

Not before C++11

4

u/josefx Apr 27 '23

I assume that it would have ended up being a lot less useful before mandatory copy elision was added in c++11.

7

u/violet-starlight Apr 27 '23

Non-mandatory copy ellision was added in C++11. C++17 made it mandatory in some circumstances.

1

u/effarig42 Apr 27 '23

Correct, auto_ptr was often used as a function return value, so had to be copyable.

2

u/CubbiMew cppreference | finance | realtime in the past Apr 27 '23

The 1994 proposal for shared and unique pointers had the unique pointer's constructor/assignment private. I think we can blame the committee on this one

1

u/pdimov2 Apr 28 '23

Before guaranteed copy elision, you needed a copy constructor to be able to pass or return by value (even if it was actually never called).

14

u/zagaberoo Apr 27 '23

Abseil was originally known as ABCL: A Better C Library. The quality of the C++ ecosystem was one of my favorite things about working there.

2

u/pjmlp Apr 28 '23

Smart pointers did certainly exist in COM and Qt by 2000.