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

Provide a clear way to get the underlying primitive value as a pointer for numerics #372

Closed danakj closed 1 year ago

danakj commented 1 year ago

Legacy code often works with pointers, and we don't want to require applications to write int32_t in order to generate an int32_t* for a function call.

But also &i32var.primitive_value is out, we don't typically want to ever write .primitive_value.

So we should provide access to the primitive as a pointer. It can't be an implicit conversion, and we can't overload operator& (which is a bad idea anyway) because pointers to safe numerics are valid.

So we can mimic containers here and provide .as_ptr() and .as_mut_ptr() to give a pointer to the inner thing.