Date: Fri, 4 Jul 2025 09:36:01 +0100
On Fri, Jul 4, 2025 at 3:17 AM JJ Marr wrote:
>
> consteval const char* c_str() const { return define_static_string(*this); }
I think this is a really cool idea except for when a naive person
encounters a compiler error for trying to use it at runtime. Ideally
the line of code would be something like:
consteval char const *c_str() const
[[explain : consteval : "This method is consteval and cannot be
used at runtime as "
"it would require dynamic memory
allocation to append a null "
"terminator to the string
(basic_string_view doesn't have a "
"null terminator)" ]]
{
return define_static_string(*this);
}
And so then the compiler error would tell the programmer exactly why
they can't use it. I'd also like to see the same kind of thing for
when a method is 'delete'ed, e.g.:
MyClass::MyClass(MyClass &&) = delete
[[explain : delete : "This constructor is deleted because you
cannot move a "
"synchronisation object without affecting
other threads "
"that may be waiting on it " ]];
>
> consteval const char* c_str() const { return define_static_string(*this); }
I think this is a really cool idea except for when a naive person
encounters a compiler error for trying to use it at runtime. Ideally
the line of code would be something like:
consteval char const *c_str() const
[[explain : consteval : "This method is consteval and cannot be
used at runtime as "
"it would require dynamic memory
allocation to append a null "
"terminator to the string
(basic_string_view doesn't have a "
"null terminator)" ]]
{
return define_static_string(*this);
}
And so then the compiler error would tell the programmer exactly why
they can't use it. I'd also like to see the same kind of thing for
when a method is 'delete'ed, e.g.:
MyClass::MyClass(MyClass &&) = delete
[[explain : delete : "This constructor is deleted because you
cannot move a "
"synchronisation object without affecting
other threads "
"that may be waiting on it " ]];
Received on 2025-07-04 08:36:11