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

Is sus::mem::replace just std::exchange? #252

Closed nigeltao closed 1 year ago

nigeltao commented 1 year ago

https://github.com/chromium/subspace/blob/4273d92da22dd5f8fd9eef83aad76049be4df155/subspace/mem/replace.h#L33-L40

Is sus::mem::replace the same as std::exchange? Even if it's not exactly the same, for some C++ language lawyer reasons beyond my understanding (e.g. const-ness, move/copy constructors, rvalue references, whatever), perhaps renaming sus::mem::replace to sus::mem::exchange would make Subspace more familiar to a C++ programmer like me.

Admittedly, being in mem, this might make it more confusable with the unrelated std::atomic<T>::exchange.

Even if you don't rename the function, it might still be worth mentioning std::exchange (and how it's similar or different) in the sus::mem::replace doc comment.

danakj commented 1 year ago

Addressing naming, I am more interested in naming consistency with std::mem::replace as this library is largely an implementation of std in terms of C++. Adding a comment is a great point, thanks.

nigeltao commented 1 year ago

Fair enough.

In case anyone else is initially confused, the std::exchange that I referred to is in C++'s standard library. The std::mem::replace that danakj referred to is in Rust's standard library.