Thread overview
traits getOverload of a template method
Feb 06, 2014
QAston
Jan 26, 2016
ZombineDev
Sep 10, 2018
Timoses
Sep 10, 2018
aliak
Sep 10, 2018
aliak
Sep 11, 2018
Basile B.
February 06, 2014
How do i get aliases to overloads of a template method like

Class A
{
    int a(T)(T tq,T tw);
    int a(T)(T tq);
}
__traits(getOverloads, A, "a(int)")doesnt work
January 26, 2016
On Thursday, 6 February 2014 at 23:06:03 UTC, QAston wrote:
> How do i get aliases to overloads of a template method like
>
> Class A
> {
>     int a(T)(T tq,T tw);
>     int a(T)(T tq);
> }
> __traits(getOverloads, A, "a(int)")doesnt work

Bump. I also have a similar problem. I have a module with two function templates that are overloaded (they have the same name, but different sets of parameters) and I need to select one of them so I can cast it to a function with the @nogc attribute, similar to this: http://p0nce.github.io/d-idioms/#Bypassing-@nogc.

```
// move has two overloads: `T move(T)(ref T)` and `void move(T)(ref T, ref T)`
// and I need to select the second one here:
cast(FT)(move!int)(arg1, arg2)

```
Otherwise I get "Error: template std.algorithm.mutation.move matches more than one template declaration".
September 10, 2018
On Thursday, 6 February 2014 at 23:06:03 UTC, QAston wrote:
> How do i get aliases to overloads of a template method like
>
> Class A
> {
>     int a(T)(T tq,T tw);
>     int a(T)(T tq);
> }
> __traits(getOverloads, A, "a(int)")doesnt work

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?
September 10, 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);

??
September 10, 2018
On Monday, 10 September 2018 at 13:46:08 UTC, aliak wrote:
> On Monday, 10 September 2018 at 12:57:25 UTC, Timoses wrote:
>>
>> 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);
>
> ??

With the Range arg as well of course.
September 11, 2018
On Thursday, 6 February 2014 at 23:06:03 UTC, QAston wrote:
> How do i get aliases to overloads of a template method like
>
> Class A
> {
>     int a(T)(T tq,T tw);
>     int a(T)(T tq);
> }
> __traits(getOverloads, A, "a(int)")doesnt work

Support for template in the getOverloads trait has been added recently.
You have to set an optional trailing parameter to `true`:

```
class A
{
    int a(T)(T,T){}
    int a(T)(T){}
}

enum include_templates = true;
static foreach (overload; __traits(getOverloads, A, "a", include_templates))
    pragma(msg, overload.stringof);
```

> a(T)(T, T)
> a(T)(T)

specs: https://dlang.org/spec/traits.html#getOverloads