CppCoreGuidelines
CppCoreGuidelines copied to clipboard
gsl::not_null conversion operator
An issue raised on the Microsoft/GSL that requests a conversion operator on gsl::not_null for non-copy constructible types (Microsoft/GSL#991).
Would the Guidelines editors like to see something like this added for gsl::not_null?
This is consistent with what we've done for the base() members of iterator adaptors in C++20, to support move-only iterators.
Should the const& one really return a reference though? My gut feeling is that for this type both should return by value, although I haven't given it much thought.
Editors call: Would you please write up some pros and cons?
This issue had come up in gsl-lite as well, and we decided to always return a value type from implicit conversion operators. The reasons are discussed in the comment here:
https://github.com/gsl-lite/gsl-lite/blob/a8c7e5bbbd08841836f9b92d72747fb8769dbec4/include/gsl/gsl-lite.hpp#L3007-L3034