Output Range Problem? How to make it work?

apz28 home at home.com
Mon Oct 11 00:19:44 UTC 2021


import std.range.primitives: isOutputRange;

     @safe:

     struct Buffer
     {
     @safe:

         void put(char c)
     	{}
         void put(scope const(char)[] s)
         {}
     }

     struct Foo
     {
     @safe:

         string toString()
     	{return null;}

         ref Writer toString(Writer, Char)(return ref Writer sink)
         if (isOutputRange!(Writer, Char) && isSomeChar!Char)
         {return sink;}

         string toString(const(char)[] fmt)
         {return null;}
     }

     void main()
     {	
         Buffer buffer;
         Foo foo;
         foo.toString(buffer);
     }


/* Getting this error
onlineapp.d(34): Error: none of the overloads of `toString` are 
callable using argument types `(Buffer)`, candidates are:
onlineapp.d(19):        `onlineapp.Foo.toString()`
onlineapp.d(26):        `onlineapp.Foo.toString(const(char)[] 
fmt)`
onlineapp.d(22):        `toString(Writer, Char)(return ref Writer 
sink)`
*/


More information about the Digitalmars-d-learn mailing list