On 25.09.2012 13:53, Manu wrote:> So I have this recurring pattern, it's
really starting to annoy me.
> It stems from the fact that a function prototype and the definition can
> not appear in the same file in D (as it can in C/C++)
> Eg,
>
[...]
> I also have numerous more advanced cases of the same problem, and
> becomes even more unsightly when used in structs to emulate dynamic
> linkage to static methods of C++ classes.
>
> The solution is seemingly trivial; allow function prototypes and
> definitions to exist in the same file, like in C/C++.
>
I think this should be allowed, aswell as implementing forward declared
enums and structs (IIRC the compiler even has some error messages that
suggest that it is intended).
As a workaround, you could put your prototypes into a struct and
generate the declarations for the static linking and the stubs for
dynamic linking from their declarations and run your magic on the
members of "prototypes":
struct prototypes
{
void fun1(int a, int b);
void fun2(int a, int b);
}
mixin(magic([__traits(allMembers, prototypes)])
That way you don't put the symbols into the same scope as the
prototypes, and you will not add new symbols to the same scope that you
are iterating over.