Is implicit string literal concatenation a good thing?

bearophile bearophileHUGS at lycos.com
Sun Feb 22 18:29:28 PST 2009


Denis Koroskin:
> bearophile:
> > 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";

In this thread I was talking about the concat of true strings, not of generic objects:
auto bar = foo  ~ ("123" ~  "456");

Are you saying that the concat operation of
"123" ~  "456"
has a different (invisible) "operator" precedence of:
"123" "456" ?
If this is true, then the ~ isn't a fully drop-in replacement for the automatic concat of strings as done in C...

Bye,
bearophile



More information about the Digitalmars-d mailing list