April 19, 2018
https://issues.dlang.org/show_bug.cgi?id=18779

          Issue ID: 18779
           Summary: StatsCollector empty doesn't take into account the
                    parent allocator
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: trivial
          Priority: P1
         Component: phobos
          Assignee: nobody@puremagic.com
          Reporter: edi33416@gmail.com

Currently, std.experimental.allocator.building_blocks.StatsCollector does not forward to the parent allocator, but instead, makes an assumption based on the `bytesUsed` option.

`empty` is not the StatsCollector's decision to make, since the parent allocator might have a different logic based on empty, than just matching allocations with deallocations.

Please see the example below; adding the unittest in stats_collector.d will trigger the assert

```
@system unittest
{
    import std.experimental.allocator.mallocator : Mallocator;
    import std.typecons : Ternary;

    static struct MyAlloc
    {
        pure nothrow @safe @nogc
        Ternary empty()
        {
            return Ternary.no;
        }

        enum uint alignment = platformAlignment;
        void[] allocate(size_t n) { return Mallocator.instance.allocate(n); }
        bool deallocate(void[] b) { return Mallocator.instance.deallocate(b); }

        static MyAlloc instance;
    }

    StatsCollector!(MyAlloc, Options.all) a;
    auto buf = a.allocate(42);
    a.deallocate(buf);
    assert(a.empty == Ternary.no); // fails
}
```

--