Thread overview | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
April 11, 2018 Mission impossible | ||||
---|---|---|---|---|
| ||||
struct S { static void func(T)(uint a, T t) { } static void func() { } } Your mission, Jim, should you choose to accept it, is this: Get a pointer to the version of the function that accepts no arguments. As always, should you or any of your Force be caught or killed, the Secretary will disavow any knowledge of your actions. This disc will self-destruct in ten seconds. Good luck, Jim. |
April 11, 2018 Re: Mission impossible | ||||
---|---|---|---|---|
| ||||
Posted in reply to Shachar Shemesh | On Wednesday, 11 April 2018 at 08:36:41 UTC, Shachar Shemesh wrote:
> struct S {
> static void func(T)(uint a, T t) {
> }
>
> static void func() {
> }
> }
>
> Your mission, Jim, should you choose to accept it, is this:
>
> Get a pointer to the version of the function that accepts no arguments.
>
> As always, should you or any of your Force be caught or killed, the Secretary will disavow any knowledge of your actions. This disc will self-destruct in ten seconds.
>
> Good luck, Jim.
I suppose __traits(getOverloads) doesn't work because of a bug ?
|
April 11, 2018 Re: Mission impossible | ||||
---|---|---|---|---|
| ||||
Posted in reply to Basile B. | On Wednesday, 11 April 2018 at 08:47:12 UTC, Basile B. wrote: > On Wednesday, 11 April 2018 at 08:36:41 UTC, Shachar Shemesh wrote: >> struct S { >> static void func(T)(uint a, T t) { >> } >> >> static void func() { >> } >> } >> >> Your mission, Jim, should you choose to accept it, is this: >> >> Get a pointer to the version of the function that accepts no arguments. >> >> As always, should you or any of your Force be caught or killed, the Secretary will disavow any knowledge of your actions. This disc will self-destruct in ten seconds. >> >> Good luck, Jim. > > I suppose __traits(getOverloads) doesn't work because of a bug ? The template hides any other overloads that func() has: https://run.dlang.io/is/yMJXRz I'm not sure if its a bug though |
April 11, 2018 Re: Mission impossible | ||||
---|---|---|---|---|
| ||||
Posted in reply to Basile B. | On Wednesday, 11 April 2018 at 08:47:12 UTC, Basile B. wrote: > On Wednesday, 11 April 2018 at 08:36:41 UTC, Shachar Shemesh wrote: >> struct S { >> static void func(T)(uint a, T t) { >> } >> >> static void func() { >> } >> } >> >> Your mission, Jim, should you choose to accept it, is this: >> >> Get a pointer to the version of the function that accepts no arguments. >> >> As always, should you or any of your Force be caught or killed, the Secretary will disavow any knowledge of your actions. This disc will self-destruct in ten seconds. >> >> Good luck, Jim. > > I suppose __traits(getOverloads) doesn't work because of a bug ? That'd be https://issues.dlang.org/show_bug.cgi?id=16206. Reorder the two functions, and it works. -- Simen |
April 11, 2018 Re: Mission impossible | ||||
---|---|---|---|---|
| ||||
Posted in reply to Basile B. | On Wednesday, April 11, 2018 08:47:12 Basile B. via Digitalmars-d wrote:
> On Wednesday, 11 April 2018 at 08:36:41 UTC, Shachar Shemesh
>
> wrote:
> > struct S {
> >
> > static void func(T)(uint a, T t) {
> > }
> >
> > static void func() {
> > }
> >
> > }
> >
> > Your mission, Jim, should you choose to accept it, is this:
> >
> > Get a pointer to the version of the function that accepts no arguments.
> >
> > As always, should you or any of your Force be caught or killed, the Secretary will disavow any knowledge of your actions. This disc will self-destruct in ten seconds.
> >
> > Good luck, Jim.
>
> I suppose __traits(getOverloads) doesn't work because of a bug ?
It looks like having the templated function makes it so that __traits(getOverloads, ...) gives an empty AliasSeq. It's probably something that got missed when it was made possible to overload templated functions with non-templated functions.
- Jonathan M Davis
|
April 11, 2018 Re: Mission impossible | ||||
---|---|---|---|---|
| ||||
Posted in reply to Shachar Shemesh | On 11/04/2018 8:36 PM, Shachar Shemesh wrote:
> struct S {
> static void func(T)(uint a, T t) {
> }
>
> static void func() {
> }
> }
>
> Your mission, Jim, should you choose to accept it, is this:
>
> Get a pointer to the version of the function that accepts no arguments.
>
> As always, should you or any of your Force be caught or killed, the Secretary will disavow any knowledge of your actions. This disc will self-destruct in ten seconds.
>
> Good luck, Jim.
import std.stdio;
void main()
{
writeln("Hello D ", &wrapper!(S, "func"));
wrapper!(S, "func");
}
struct S {
static void func(T)(uint a, T t) {
writeln("a");
}
static void func() {
writeln("b");
}
}
pragma(inline, true)
auto wrapper(T, string name, Args...)(Args args) {
mixin("return T." ~ name ~ "(args);");
}
|
April 11, 2018 Re: Mission impossible | ||||
---|---|---|---|---|
| ||||
Posted in reply to Uknown | On 11/04/18 11:51, Uknown wrote: > On Wednesday, 11 April 2018 at 08:47:12 UTC, Basile B. wrote: >> On Wednesday, 11 April 2018 at 08:36:41 UTC, Shachar Shemesh wrote: >>> struct S { >>> static void func(T)(uint a, T t) { >>> } >>> >>> static void func() { >>> } >>> } >>> >>> Your mission, Jim, should you choose to accept it, is this: >>> >>> Get a pointer to the version of the function that accepts no arguments. >>> >>> As always, should you or any of your Force be caught or killed, the Secretary will disavow any knowledge of your actions. This disc will self-destruct in ten seconds. >>> >>> Good luck, Jim. >> >> I suppose __traits(getOverloads) doesn't work because of a bug ? > > The template hides any other overloads that func() has: IF it is defined before it. If it is defined after it, it does not (but it is then possible that the non-template version hides the template one). The problem is that S has two members called "func". One is a function, and the other is a template. "getOverloads" is not built to distinguish between the two. > I'm not sure if its a bug though What else is it? Shachar |
April 11, 2018 Re: Mission impossible | ||||
---|---|---|---|---|
| ||||
Posted in reply to Shachar Shemesh | On Wednesday, 11 April 2018 at 08:59:36 UTC, Shachar Shemesh wrote:
> On 11/04/18 11:51, Uknown wrote:
>> On Wednesday, 11 April 2018 at 08:47:12 UTC, Basile B. wrote:
>>> On Wednesday, 11 April 2018 at 08:36:41 UTC, Shachar Shemesh [...]
> What else is it?
>
> Shachar
I thought there was a relevant rule about member templates, but there isn't any such thing. My bad
|
April 11, 2018 Re: Mission impossible | ||||
---|---|---|---|---|
| ||||
Posted in reply to Shachar Shemesh | If it doesn't work, hack it: struct S { static void func(T)(uint a, T t) { } static void func1() { } alias func=func1; } |
Copyright © 1999-2021 by the D Language Foundation