Zig vs D generics

Paulo Pinto pjmlp at progtools.org
Mon Oct 10 18:23:42 UTC 2022


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.


More information about the Digitalmars-d mailing list