File.seek() offset parameter should be enum, not int.

Bastiaan Veelo Bastiaan at Veelo.net
Mon Apr 8 14:49:06 UTC 2019


On Monday, 8 April 2019 at 13:56:24 UTC, Bastiaan Veelo wrote:
> 1) Change the enum containing SEEK_* to a named enum,
> 2) Change the type of the origin parameter to this enum.
> 3) Document.
>
> Would we need to keep the original signature around as an 
> overload to prevent code breakage? Maybe not? But if so, would 
> that work without conflicts?

I don't think an overload is necessary. I am thinking along these 
lines [1]

import std.stdio;

enum SEEK
{
     /// Offset is relative to the beginning
     SET,
     /// Offset is relative to the current position
     CUR,
     /// Offset is relative to the end
     END
}
enum SEEK_SET = SEEK.SET;
enum SEEK_CUR = SEEK.CUR;
enum SEEK_END = SEEK.END;

void seek(long offset, int origin = SEEK_SET) {writeln("orig");} 
// Original, not called anymore.
void seek(long offset, SEEK origin = SEEK.SET) {writeln("new");}

void main()
{
     seek(0, SEEK_CUR); // Legacy
     seek(0, SEEK.CUR); // Recommended
}

[1] https://run.dlang.io/is/MllZ5Q


More information about the Digitalmars-d mailing list