Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Making Your Own Container Compatible with C++20 Ranges (reedbeta.com)
74 points by ingve on March 22, 2021 | hide | past | favorite | 10 comments


This kind of thing is easily one of my favorite pieces of C++. I used to be the OS lead for a proprietary C++14 RTOS, and being able to build our own intrusive collections libraries that were able to use all the same syntax sugar as the STL was absolutely killer.

IMO, all systems languages should be expressive enough to implement their standard libraries and containers as normal language code, but sadly that isn't always the case.


> One of my fundamental aims for C++ is (from the very start in 1979) to provide equally good support for user-defined and built-in types. For example, I’d like to be able to build an integer type that is as good as the built-in int in every way (with the possible exception of compile time).

~ Bjarne Stroustrup, How can you be so certain? (2019)


Which made me an early adopter in 1993 for MS-DOS, as C already felt primitive back then.

However I still dream of the day where static analysis can fix all possible security issues.


Which systems languages can't do this?


The only one I'm aware of is Golang.


I'm not sure if this situation has improved in C++20, but writing iterator types properly in classic C++ really sucks, and this article glosses over a lot of the details.

I've always used Boosts iterator_facade to do this: https://www.boost.org/doc/libs/1_75_0/libs/iterator/doc/iter... , which requires you only implement a maximum of 6 functions for any iterator type.


Boost.STLInterfaces provides a more modern alternative to iterator_facade.

https://www.boost.org/doc/libs/1_75_0/doc/html/stl_interface...


Yes, indeed! Thanks


The author gave a great talk on this at cppcon last year: https://www.youtube.com/watch?v=JByCzWaGxhE


I find it pretty funny that the article opens with "so we don't need all that SFINAE junk anymore" and then proceeds to spend pages upon pages explaining the other junk we need in its place :-)

I know, apples to oranges, the SFINAE bit was about concepts, not iterators. Still, pretty funny.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: