chromium / subspace

A concept-centered standard library for C++20, enabling safer and more reliable products and a more modern feel for C++ code.; Also home of Subdoc the code-documentation generator.
https://suslib.cc
Apache License 2.0
89 stars 15 forks source link

Add Iterator::deref() for allowing use of smart pointers in iterators but use their inner value as a reference #365

Open danakj opened 1 year ago

danakj commented 1 year ago

Instead of

sus::move(it).map([](auto&& x) { return *x; }).map([](InnerT& t) { ... })

It would be nice

sus::move(it).deref().map([](InnerT& t) { ... })

Which does the same thing but more clear.

Smart pointers are super common in C++ so this is important, and the simple map function is very verbose compared to rust's .map(|x| *x).

This way code does not need to worry about what smart pointers are in use, they never appear in the signature either.

Currently some C++ smart pointers end up with implicit conversions to avoid the work of writing out their type and the dereferences.