string-view-lite
string-view-lite copied to clipboard
Prevent construction/conversion from nullptr
When introducing string_view into an old codebase, it is quite easy to accidentally leave nonsensical assignments from or comparisons to nullptr in your code. Adding a deleted constructor as follows allows developers to easily identify the offending assignments and comparisons:
#if nssv_CPP11_OR_GREATER
nssv_constexpr basic_string_view( std::nullptr_t ) nssv_noexcept = delete;
#endif
C++23 will also disallow constructing std::basic_string_view from nullptr: https://github.com/cplusplus/papers/issues/887
Ah, thank you for the pointer Moritz @mbs-c, I wasn't yet aware of this.
I'll add the proposed constructor.