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

AsRef<T> and AsSlice<T> #243

Open danakj opened 1 year ago

danakj commented 1 year ago

AsRef being singular and AsSlice being plural. Need Mut siblings as well.

Many things can produce a ref/slice without being a ref/slice. Vec is a Slice, has Slice methods. But is a string? Is an unordered map?

But what if you want to receive anything that can give a ref/slice?

Rust has AsRef, but omits AsSlice though many types have .as_slice() which means the caller must do the production.

We could have fn(AsSlice const auto& s) { s.as_slice()…. }

https://youtu.be/Tz5drzXREW0 talks about this desire to write generic code over slice-able things.