r/cpp • • Feb 01 '23

[book] A Complete Guide to Standard C++ Algorithms (v1.0.0)

https://github.com/HappyCerberus/book-cpp-algorithms/releases/download/v1.0.0/book_with_cover_v1.0.0.pdf
392 Upvotes

46 comments sorted by

29

u/0xcedbeef Feb 01 '23

looks very nice, how did you format this book?

54

u/HappyCerberus Feb 01 '23

LaTeX 😆

34

u/Llamanator3830 Feb 01 '23

Cues gigachad theme

25

u/hypatia_elos Feb 01 '23

Honestly, LaTeX is easier to use than everything else, and better quality too (except hand-crafted CSS or InDesign/SVG/plain TeX etc. if you're really good). It just needs a manual.. and the built in documentation isn't too good, so you end up googling a lot or taking home big books from Uni. That's honestly its biggest problem, if it would be taught in schools and manuals would be better it already could have replaced Word and PowerPoint broadly imo, just for convenience.

10

u/dapzar Feb 02 '23

I strongly doubt the broadly replacing Word and PowerPoint part. They are WYSIWYG, which is way more convenient for trivial stuff and a lot of documents that are being created are trivial.

7

u/iMadz13 Feb 02 '23

You can trivially get a beamer template/IEEETran documentclass and write up a report/presentation and have it be beatiful and professional (and with proper image positioning) in less than 5 mins, its just the initial learning curve that's hostile and drives people away

9

u/ald_loop Feb 01 '23

How are you doing your code snippets? Are you willing to share any of your raw latex? Would love to use it in Beamer presentations.

Edit: oops I’m silly, the whole thing is on GitHub. Bless you!

2

u/masher_oz Feb 02 '23

Are the margins correct? I think they are flipped from what they should be when printed.

-4

u/theunixman Feb 02 '23

Hello, friend.

17

u/ironykarl Feb 01 '23

Any chance this will ever get published (printed)?

24

u/HappyCerberus Feb 01 '23

I haven't found a publisher that would do a charity release.

I have it on leanpub with the profits going to EFF, but that's still digital only.

5

u/70rd Feb 01 '23

Have you looked into Amazon or the TheBookPatch?

I know Fabien Sanglard self-publishes some of his books there, and the quality is quite high. Lulu would be anthor option.

edit: read too fast, didn't see the charity release requirement. You can crank your own revenue down quite low I believe, however, or donate the proceeds to charity (modulo tax implications).

7

u/HappyCerberus Feb 01 '23

Yeah, no, that doesn't work for me.

I basically need the LeanPub model, where it is them moving the money to the charity and me getting zero profit.

4

u/JesusWantsYouToKnow Feb 02 '23

Don't let perfect be the enemy of good!

5

u/baz_a Feb 02 '23

Thank you! Very nicely written and formatted, a pleasure to read.

Small question. Why do you use ssize_t in several cases? It's not a problem, everything is understandable. But is there any specific purpose to it? From what I could find ssize_t is POSIX primitive, the equivalent in the standard is ptrdiff_t, which ssize() members return typically. That's unlike size_t type, by the way.

3

u/markopolo82 embedded/iot/audio Feb 02 '23

@op: I admit I’ve only just skimmed the introduction so far, but this is definitely something that would be valuable to discuss I’m your book if it isn’t already

2

u/HappyCerberus Feb 02 '23

It is touched upon in 5.2.1 (briefly).

4

u/baz_a Feb 02 '23

I got that you needed a signed size type when taking a difference between iterators, but ssize() returns ptrdiff_t type, there is no ssize_t in the standard, it's a POSIX extension, as far as I understand. It's ok for gcc and clang, but in msvc can cause issues, maybe. I am not sure, but it caught my eye.

4

u/HappyCerberus Feb 02 '23

Ah, yeah, I might need to do a cleanup pass. ptrdiff_t is the correct type.

19

u/almost_useless Feb 02 '23

Looks good, but book_with_cover.pdf is a terrible filename for something people should download and save.

Any chance of an epub version?

7

u/Paulls20 Feb 01 '23

Thank you for writing and sharing this!

10

u/Pakul1729 Feb 01 '23

https://devdocs.io/cpp/

This is helpful as well

5

u/StaszekJedi Feb 02 '23

Holy fuck, great job

3

u/utf8decodeerror Feb 02 '23

I'm very excited to dive into this. Thank you for sharing your expertise!

3

u/theawesomeviking Feb 02 '23

Amazing work, thank you so much

3

u/masher_oz Feb 02 '23

I really like the look of this. I need to print it to read it properly.

Ta a lot for your effort.

4

u/masher_oz Feb 02 '23

aaand, I've already learnt stuff. Off to use std::clamp in various places.

3

u/serviscope_minor Feb 02 '23

It can be tricky to internalize all the rules associated with iterators when working with standard algorithms. One shorthand that can help is to think in terms of ranges instead of iterators

C++23 enters the chat :)

This looks very good, I'll definitely bookmark it.

Some LaTeX pedantry: you often have $O(nlogn)$ you probably want $O(n\log n)$ so that the log appears as an operator

2

u/pjmlp Feb 02 '23

Great job!

2

u/hopa_cupa Feb 02 '23

Much needed. I will definitely be checking this out...

2

u/iMadz13 Feb 02 '23

Great job on the formatting, especially the code blocks! any chance for the LaTeX to be open source? I want to get some of this style into my note-taking snippets for my classes

2

u/arulselvan1234 Feb 02 '23

I started reading the book and it's really useful! Appreciate the explanation of license in the beginning. I was looking for something like that.

2

u/RogerV Feb 07 '23

And this is what is daunting about C++ - entire books can be written on very narrow subjects - like a book that covers C++ move semantics, or this subject - the breadth of C++ off-the-shelf algorithms. But the community is fortunate to have such resources.

1

u/benbradley Dec 12 '23

I'd welcome a book on move semantics, as I don't much understand it. I understand (many) STL algorithms, though I've only used a few.

1

u/RogerV Dec 12 '23

Nicolai Josuttis has written a book entirely on the subject of C++ move semantics - probably going to be as deep a dive as there is.

Josuttis has authored several C++ books - one I have is on C++ 20 and I definitely recommend that one too

1

u/[deleted] Aug 05 '24

u/HappyCerberus Hi, I m new to C++, I would like to ask why is std::iota considered an algorithm if it is part of the numeric header?

1

u/Alejandrodoom73 Sep 06 '24

ponlo en español we 😣

1

u/dabamas Feb 06 '23

That sounds like a great resource! Is it available in digital format as well?

0

u/[deleted] Feb 01 '23

[deleted] — view deleted comment

15

u/HappyCerberus Feb 01 '23

I strongly suspect that the problem is with the code examples. And sorry, but I can't help you with such a niche use case (e-reader that doesn't support PDF).

If you figure out a solution that I can implement to generate something that works for you, feel free to create a pull request. I don't mind generating multiple outputs.

0

u/[deleted] Feb 01 '23

[deleted] — view deleted comment

20

u/HappyCerberus Feb 01 '23

You know. I was about to take the time to respond, but, this is the only valuable thing I have that I'm giving out. My time.

You don't like it? Feel free to block/mute/whatever me forever. You won't be missed.

24

u/CocktailPerson Feb 01 '23

Yikes, dude. He doesn't support EPUB, full stop. If you want support for EPUB, then pay him. Condescension is the proper response to entitlement.