www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - traits getOverload of a template method

reply "QAston" <qaston gmail.com> writes:
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
Feb 06 2014
next sibling parent ZombineDev <valid_email he.re> writes:
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".
Jan 26 2016
prev sibling next sibling parent reply Timoses <timosesu gmail.com> writes:
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?
Sep 10 2018
parent reply aliak <something something.com> writes:
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); ??
Sep 10 2018
parent aliak <something something.com> writes:
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.
Sep 10 2018
prev sibling parent Basile B. <b2.temp gmx.com> writes:
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
Sep 11 2018