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

bauss jj_1337 at live.dk
Mon Apr 8 16:03:42 UTC 2019


On Monday, 8 April 2019 at 14:49:06 UTC, Bastiaan Veelo wrote:
> 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

You should just have created a PR in phobos and left discussion 
within there instead of here.


More information about the Digitalmars-d mailing list