How do I assign attributes of a function to another function?
Li30U
mrnazar44 at gmail.com
Fri Nov 5 06:19:16 UTC 2021
I am creating a templated object that is a storehouse for a heap
object and executes their methods and returns an array of
results. With the help of a template, I want to achieve this, but
I want to assign the same attributes to the function. How can one
pass the attributes of a function to another function?
```d
template Group(T, int objects)
{
struct Group
{
enum __length = __traits(allMembers, T).length;
T[objects] __objects;
this(T[objects] __objctor) @safe
{
__objects = __objctor;
}
static foreach (member; __traits(allMembers, T))
{
static if ( __traits(getVisibility,
__traits(getMember, T, member)) != "private" &&
__traits(getVisibility,
__traits(getMember, T, member)) != "protected")
{
static if (isFunction!(__traits(getMember, T,
member)))
{
mixin ("ReturnType!(__traits(getMember, T,
member))[] " ~ member ~ "(Parameters!(__traits(getMember, T,
member)) args)
{
ReturnType!(__traits(getMember, T,
member))[] results;
foreach (e; __objects)
results ~= e." ~ member ~ "(args);
return results;
}");
}else
static if (member != "Monitor")
{
mixin ("typeof(__traits(getMember, T,
member))[] " ~ member ~ "()
{
typeof(__traits(getMember, T, member))[]
results;
foreach (e; __objects)
results ~= e." ~ member ~ ";
return results;
}");
}
}
}
}
}
```
More information about the Digitalmars-d-learn
mailing list