Thread overview
Appender example doesn't work with GDC. GDC bug?
Dec 28
BoraxMan
Dec 28
BoraxMan
Dec 28
BoraxMan
December 28
The example for appender located here, does not compile with GDC.

https://dlang.org/library/std/array/appender.html

void main()
{
    import std.array;
    import std.stdio: write, writeln, writef, writefln;
    auto w = appender!string;
    // pre-allocate space for at least 10 elements (this avoids costly reallocations)
    w.reserve(10);
    assert(w.capacity >= 10);

    w.put('a'); // single elements
    w.put("bc"); // multiple elements

    // use the append syntax
    w ~= 'd';
    w ~= "ef";

    writeln(w[]); // "abcdef"


}

For the line "Writeln(w[]);" GDC reports "error: no [] operator overload for type Appender!string".

It works with DMD.

Time to file  a bug report with GCC-GDC?

December 28
On Saturday, 28 December 2019 at 03:08:48 UTC, BoraxMan wrote:
> For the line "Writeln(w[]);" GDC reports "error: no [] operator overload for type Appender!string".

I think that is just a broken example. Pretty sure it should be `w.data` instead of `w[]`.
December 28
On 28/12/2019 4:30 PM, Adam D. Ruppe wrote:
> On Saturday, 28 December 2019 at 03:08:48 UTC, BoraxMan wrote:
>> For the line "Writeln(w[]);" GDC reports "error: no [] operator overload for type Appender!string".
> 
> I think that is just a broken example. Pretty sure it should be `w.data` instead of `w[]`.

This was added 5 months ago.

The example is correct.

https://github.com/dlang/phobos/commit/fbbdb721a5424748a485b5b8425e986fff4511a1

FYI: the current version of gdc exists mostly to bootstrap future versions of gdc (because of rules surrounding gcc).

You will get instances like this where your gdc build will be severely out of date. I would not recommend it for a new(-ish) user as of this moment.
December 28
On Saturday, 28 December 2019 at 03:45:04 UTC, rikki cattermole wrote:
> On 28/12/2019 4:30 PM, Adam D. Ruppe wrote:
>> On Saturday, 28 December 2019 at 03:08:48 UTC, BoraxMan wrote:
>>> For the line "Writeln(w[]);" GDC reports "error: no [] operator overload for type Appender!string".
>> 
>> I think that is just a broken example. Pretty sure it should be `w.data` instead of `w[]`.
>
> This was added 5 months ago.
>
> The example is correct.
>
> https://github.com/dlang/phobos/commit/fbbdb721a5424748a485b5b8425e986fff4511a1
>
> FYI: the current version of gdc exists mostly to bootstrap future versions of gdc (because of rules surrounding gcc).
>
> You will get instances like this where your gdc build will be severely out of date. I would not recommend it for a new(-ish) user as of this moment.

Adams suggestion does work.  Using w.data in place of w[] provides the expected result.

The problem is that GDC is part of GCC now, and part of the Fedora installation I'm using.  I take it then if I am to start a new project where I may end up providing binaries, I should eschew using the GDC compiler and use LDC instead?  This kind of consideration is not an issue when using C or C++ (at least in Linux).  By default the choice is correct.
December 28
On Saturday, 28 December 2019 at 08:25:16 UTC, BoraxMan wrote:

> The problem is that GDC is part of GCC now, and part of the Fedora installation I'm using.  I take it then if I am to start a new project where I may end up providing binaries, I should eschew using the GDC compiler and use LDC instead?  This kind of consideration is not an issue when using C or C++ (at least in Linux).  By default the choice is correct.

If by "correct" you mean the latest and greatest in terms of language and library features, then that means DMD. GDC doesn't have the sort of manpower behind that gcc and g++ benefit from. As I understand it, the version that ships with GCC was further hampered by being locked in quite some time ago due to the GCC release cycle.

You have three D compilers to choose from. Use the one that meets your needs. They all can put out compatible binary output on any given platform.
December 28
On Saturday, 28 December 2019 at 10:41:56 UTC, Mike Parker wrote:
> On Saturday, 28 December 2019 at 08:25:16 UTC, BoraxMan wrote:
>
>> The problem is that GDC is part of GCC now, and part of the Fedora installation I'm using.  I take it then if I am to start a new project where I may end up providing binaries, I should eschew using the GDC compiler and use LDC instead?  This kind of consideration is not an issue when using C or C++ (at least in Linux).  By default the choice is correct.
>
> If by "correct" you mean the latest and greatest in terms of language and library features, then that means DMD. GDC doesn't have the sort of manpower behind that gcc and g++ benefit from. As I understand it, the version that ships with GCC was further hampered by being locked in quite some time ago due to the GCC release cycle.
>
> You have three D compilers to choose from. Use the one that meets your needs. They all can put out compatible binary output on any given platform.

What I mean by 'correct', is that despite the fact there are different C stdlibs out there overall, there is generally one which forms the core of a Linux install, and the same is true with other unices, as far as I can tell.  For Linux, its glibc, regardless of whether I choose GCC or CLANG, the binary links to one libc, the same one.  With D though, there is a libphobos for each compiler, so if a Linux distro for example was to start packaging D software, they would probably want to settle on a specific libphobos, which means me using a different compiler would mean the end user having to bring in a second libphobos on top of the one the distro was designed around.  Then you have libraries which may also use libphobos, such as dlangui, which a program may link against.

The right compiler is the one which fits best in the "ecosystem" of my target audience, not the best for me personally.

December 28
On Saturday, 28 December 2019 at 03:08:48 UTC, BoraxMan wrote:
> The example for appender located here, does not compile with GDC.
>
> https://dlang.org/library/std/array/appender.html
>
[---snip---]
> For the line "Writeln(w[]);" GDC reports "error: no [] operator overload for type Appender!string".
>
> It works with DMD.
>
> Time to file  a bug report with GCC-GDC?

As others have already said, the example reflects the latest release, not the version gdc is based upon.

Luckily, we have been keeping archived docs for quite some time now, so you can just switch and read the correct usage examples.

https://docarchives.dlang.io/v2.076.0/phobos/index.html