digitalmars.D.learn - traits getOverload of a template method
- QAston (7/7) Feb 06 2014 How do i get aliases to overloads of a template method like
- ZombineDev (14/21) Jan 26 2016 Bump. I also have a similar problem. I have a module with two
- Timoses (20/27) Sep 10 2018 Is there any way to "select" overloaded template functions?
- aliak (8/29) Sep 10 2018 Can you either:
- aliak (2/12) Sep 10 2018 With the Range arg as well of course.
- Basile B. (16/25) Sep 11 2018 Support for template in the getOverloads trait has been added
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
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 workBump. 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
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 workIs 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
On Monday, 10 September 2018 at 12:57:25 UTC, Timoses wrote:On Thursday, 6 February 2014 at 23:06:03 UTC, QAston wrote:Can you either: alias myPeek = () => peek!(int, Endian.bigEndian, immutable(ubyte)[])(); Or alias myPeek = (size_t *index) => peek!(int, Endian.bigEndian, immutable(ubyte)[])(index); ??[...]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
On Monday, 10 September 2018 at 13:46:08 UTC, aliak wrote:On Monday, 10 September 2018 at 12:57:25 UTC, Timoses wrote:With the Range arg as well of course.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
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 workSupport 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