[ox/std] Make StringLiteral constructors consteval
All checks were successful
Build / build (push) Successful in 1m29s
All checks were successful
Build / build (push) Successful in 1m29s
This commit is contained in:
15
deps/ox/src/ox/std/stringliteral.hpp
vendored
15
deps/ox/src/ox/std/stringliteral.hpp
vendored
@ -16,24 +16,19 @@ namespace ox {
|
|||||||
* StringLiteral is used for functions that want to ensure that they are taking
|
* StringLiteral is used for functions that want to ensure that they are taking
|
||||||
* string literals, and not strings outside of the data section of the program
|
* string literals, and not strings outside of the data section of the program
|
||||||
* that might get deleted.
|
* that might get deleted.
|
||||||
* This type cannot force you to use it correctly, so don't give it something
|
|
||||||
* that is not a literal.
|
|
||||||
* If you do this:
|
|
||||||
* StringLiteral(str.c_str())
|
|
||||||
* the resulting segfault is on you.
|
|
||||||
*/
|
*/
|
||||||
class StringLiteral: public detail::BaseStringView {
|
class StringLiteral: public detail::BaseStringView {
|
||||||
public:
|
public:
|
||||||
constexpr StringLiteral() noexcept = default;
|
consteval StringLiteral() noexcept = default;
|
||||||
|
|
||||||
constexpr StringLiteral(StringLiteral const &sv) noexcept = default;
|
constexpr StringLiteral(StringLiteral const &sv) noexcept = default;
|
||||||
|
|
||||||
constexpr explicit StringLiteral(std::nullptr_t) noexcept {}
|
consteval explicit StringLiteral(std::nullptr_t) noexcept {}
|
||||||
|
|
||||||
constexpr explicit StringLiteral(const char *str, std::size_t len) noexcept: BaseStringView{str, len} {}
|
consteval explicit StringLiteral(char const *str, std::size_t const len) noexcept: BaseStringView{str, len} {}
|
||||||
|
|
||||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||||
constexpr explicit StringLiteral(char const *str) noexcept: StringLiteral{str, ox::strlen(str)} {}
|
consteval explicit StringLiteral(char const *str) noexcept: StringLiteral{str, ox::strlen(str)} {}
|
||||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||||
|
|
||||||
constexpr StringLiteral &operator=(StringLiteral const &other) noexcept {
|
constexpr StringLiteral &operator=(StringLiteral const &other) noexcept {
|
||||||
@ -42,7 +37,7 @@ class StringLiteral: public detail::BaseStringView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr const char *c_str() const noexcept {
|
constexpr char const *c_str() const noexcept {
|
||||||
return data();
|
return data();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user