Zig vs D generics
Paulo Pinto
pjmlp at progtools.org
Tue Oct 11 07:29:13 UTC 2022
On Monday, 10 October 2022 at 18:23:42 UTC, Paulo Pinto wrote:
> On Monday, 10 October 2022 at 16:59:56 UTC, Quirin Schroll
> wrote:
>> On Monday, 10 October 2022 at 14:18:52 UTC, Paulo Pinto wrote:
>>> I guess you did something wrong, :)
>>> ```cpp
>>> #include <string>
>>> #include <iostream>
>>>
>>> constexpr std::string hello() {
>>> return std::string("hello world");
>>> }
>>>
>>> int main() {
>>> static constexpr auto greeting = hello();
>>>
>>> std::cout << greeting << std::endl;
>>> }
>>> ```
>>
>> This only works because you initialize the `std::string` with
>> a literal. It fails on this:
>> ```cpp
>> return std::string("hello ") + "world";
>> ```
>
> Because that was what I was replying to in first place.
>
> As for your example, I have to cross check it on VC++ 2022
> latest and its current support for upcoming ISO C++23, and what
> ISO says about it.
And the conclusion is, when using C++ latest compliance to C++23,
VC++ 2022 19.33 complains about it, while VC++ 2022 latest is
more than happy to handle it,
VS 2022 19.33 => https://godbolt.org/z/ofes3a78z
VS 2022 latest => https://godbolt.org/z/v1Y8Ec65W
In C++23 most string related operations are now constexpr.
https://eel.is/c++draft/string.classes
More information about the Digitalmars-d
mailing list