Date: Wed, 1 May 2024 15:37:18 +0100
On Tue, Apr 30, 2024 at 3:24 PM Marcin Jaczewski wrote:
>
> Use `consteval` constructor, then only static values can be used to init object:
>
> ```
> struct StaticString
> {
> consteval StaticString(const char* c)
> {
>
> }
>
> StaticString()
> {
>
> }
>
> StaticString(const StaticString& ss)
> {
>
> }
> };
I'm trying to make a new 'efficent_string' class that only copies the
string if necessary, but it seems we would need a language change in
order to implement it. See how the following fails:
https://godbolt.org/z/667rYv56v
The problem is shown more simply in this minimalist godbolt:
https://godbolt.org/z/dE4555eEv
Or even more simply:
https://godbolt.org/z/oM13TPre9
There would need to be a language change to disambiguate and allow in
the following order:
(1) consteval calls to char (&arg)[n]
(2) non-consteval calls to char (&arg)[n]
(3) consteval calls to char const *const arg
(4) non-consteval call to char const *const arg
Then the constructor for 'efficent_string' would be able to pick out
the times when it's not necessary to copy the string.
>
> Use `consteval` constructor, then only static values can be used to init object:
>
> ```
> struct StaticString
> {
> consteval StaticString(const char* c)
> {
>
> }
>
> StaticString()
> {
>
> }
>
> StaticString(const StaticString& ss)
> {
>
> }
> };
I'm trying to make a new 'efficent_string' class that only copies the
string if necessary, but it seems we would need a language change in
order to implement it. See how the following fails:
https://godbolt.org/z/667rYv56v
The problem is shown more simply in this minimalist godbolt:
https://godbolt.org/z/dE4555eEv
Or even more simply:
https://godbolt.org/z/oM13TPre9
There would need to be a language change to disambiguate and allow in
the following order:
(1) consteval calls to char (&arg)[n]
(2) non-consteval calls to char (&arg)[n]
(3) consteval calls to char const *const arg
(4) non-consteval call to char const *const arg
Then the constructor for 'efficent_string' would be able to pick out
the times when it's not necessary to copy the string.
Received on 2024-05-01 14:37:31