Is implicit string literal concatenation a good thing?

Denis Koroskin 2korden at gmail.com
Sun Feb 22 18:10:41 PST 2009


On Mon, 23 Feb 2009 04:18:35 +0300, bearophile <bearophileHUGS at lycos.com> wrote:

> BCS:
>
>> IIRC DMD doesn't always do the constant folding (Decent has a post  
>> processed
>> view that shows this in some cases) For instance, IIRC it only does left
>> most so this:
>> char[] foo = "foo";
>> char[] bar = foo ~ "bar" ~ "baz"
>> doesn't get folded. And even if DMD were to start doing that one, there  
>> is
>> no requirement that another compiler also do it.
>
> If there are guarantees that "abc" "def" are folded at compile time,  
> then the same guarantees can be specified for "abc" ~ "def". I can't see  
> a problem.
>
> I have also compiled this code with DMD:
>
> void main() {
>     string foo = "foo";
>     string bar = foo ~ "bar" ~ "baz";
> }
>

Won't work. Imaging foo is a user-defined type with custom opCat:

auto bar = foo  ~  "123" ~  "456";

compare to:

      std::cout << "123" << "456";



More information about the Digitalmars-d mailing list