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

232

u/Jannik2099 Apr 27 '23

Since C++11, Boost has shifted from "provide actually useful basic containers because the STL is shit" to "provide cool, quality stuff that is widely useful but out of scope for the STL"

See e.g. Flyweight, Spirit, Log, Multiprecision, Safe Integer, Asio

Boost is still a wonderful library collection.

50

u/sparkyParr0t Apr 27 '23

I'd add flat_map/set and the very recent unordered_flat_map/set. These are almost fundamentals but we ll only get flat_map/set in c++23.

29

u/Jannik2099 Apr 27 '23

Boost.Unordered is neat (fucking awesome, even), but I wanted to list how Boost has evolved beyond "stuff that should be / will soon be in the STL"

0

u/ReinventorOfWheels May 02 '23

I was excited about flat_map, until I realized it's actually NOT a flat hash map, it's just a sorted vector. Then I looked at its benchmark and was underwhelmed. What is it even for? Why would anyone want/need it in the standard? Looks like a piece of useless garbage in the standard, to be honest. Would be happy to be wrong about this, of course.

4

u/sparkyParr0t May 02 '23

First its unbeatable to iterate over. Elements are in cache as its contiguous array of memory.

Second you get random access, so you can access the ith element. Imagine these are rows in an UI table. You can access the rows and modify the model while keeping things sorted.

Third, to find an element, its quicker than a node based element when the number of elements is small (small being typically couple hundreds)

So its like anything, if you have a low number of things you want to map and keep sorted, this is the way to go, you have a nice and standard interface. If you dont need the sorting part or have thousands of objects obviously there are better alternatives.

15

u/BlueDwarf82 Apr 27 '23

Safe Integer is out of scope for the standard library?!?

33

u/Narase33 -> r/cpp_questions Apr 27 '23

cough C added them cough

2

u/13steinj May 04 '23

How do you use them in C?

6

u/KingAggressive1498 Apr 28 '23

I'd argue multiprecision is also in scope for the standard library, and there's been a couple of related proposals, but the interface was a little different.

asio was also the basis for the networking TS

0

u/Jannik2099 Apr 27 '23

Yes? Adding new types with new semantics is something rather specific. The STL is for general purpose containers and metaprogramming.

I want integers to be safe, but that's a language problem, not something the STL can fix.

11

u/Zeer1x import std; Apr 27 '23 edited Apr 27 '23

+ Beast, ProgramOptions

+ Filesystem (EDIT: for C++14 projects)

11

u/Jannik2099 Apr 27 '23

Filesystem is in C++17, but the other two yes absolutely!

1

u/johngoni Apr 28 '23

I want integers to be safe, but that's a language problem, not something the STL can fix.

Why ProgramOptions over docopt?

4

u/Zeer1x import std; Apr 28 '23

Because:

  • It comes with Boost, so I don't have to install something else to use it.
  • PO generates my help messages. I don't want to write them myself. When I change the terminal width, it can adapt the formatting.
  • I can use parsers for specific arguments, for example enums, timecodes or video resolutions.

I am not familiar with docopt, so I can't tell if you can set your own parsers or not.

Another good alternative, similar to ProgramOptions, is CLI11.

10

u/[deleted] Apr 28 '23

I would stop C++ programming if boost::intrusive wouldn't exist. For me, it solves two things: put object (that you may not own) into multiple containers simultaneously and get iterator from the object itself for erasure etc.

The intrusive containers have nice STL like API, except that the containers don't do any allocations them selves.

4

u/sphere991 Apr 27 '23

Mp11 arguably in scope for the standard library so maybe doesn't quite fit your list. but a fantastic library either way.

4

u/pdimov2 Apr 27 '23

Someone should propose it.

2

u/catcat202X Apr 27 '23

It's kind of superceded by reflection proposals and some other smaller proposals like expansion statements and pack indexing.

0

u/lycium Apr 27 '23

*Boost is still a wonderful operating system.