traits getOverload of a template method

aliak something at something.com
Mon Sep 10 13:46:08 UTC 2018


On Monday, 10 September 2018 at 12:57:25 UTC, Timoses wrote:
> On Thursday, 6 February 2014 at 23:06:03 UTC, QAston wrote:
>> [...]
>
> Is there any way to "select" overloaded template functions?
>
> I require to select one of `std.bitmanip.peek`
>
>     import std.bitmanip : peek;
>     import std.system : Endian;
>     alias myPeek = peek!(int, Endian.bigEndian, 
> immutable(ubyte)[]);
>
> Error:
> template std.bitmanip.peek matches more than one template 
> declaration:
> /dlang/dmd/linux/bin64/../../src/phobos/std/bitmanip.d(3269):
>   peek(T, Endian endianness = Endian.bigEndian, R)(R range) if 
> (canSwapEndianness!T && isForwardRange!R && is(ElementType!R : 
> const(ubyte)))
> and
> /dlang/dmd/linux/bin64/../../src/phobos/std/bitmanip.d(3306):
>   peek(T, Endian endianness = Endian.bigEndian, R)(R range, 
> size_t* index) if (canSwapEndianness!T && isForwardRange!R && 
> hasSlicing!R && is(ElementType!R : const(ubyte)))
>
> How to "select" one?

Can you either:

alias myPeek = () => peek!(int, Endian.bigEndian, 
immutable(ubyte)[])();
Or
alias myPeek = (size_t *index) => peek!(int, Endian.bigEndian, 
immutable(ubyte)[])(index);

??


More information about the Digitalmars-d-learn mailing list