using Standard;
using Containers;
using Attributes;
Map(String, String).Attribute(Const) x = [&] {
Map(String, String) retval;
retval["ohai"] = "nub";
return retval;
}();
This is a trick I've used in C++- it's better than initializer lists, in my opinion. The problem is that initializing some complex types depends on referring to them- similar to using this in the initializer list. For example, my previous definition of Const depends on recursively applying Const to it's member types. This is illegal in C++, but I've decided that it will have to be legalized in "DeadMG++". Referring to a variable in it's initializer will be legal, and it will be legal to take a pointer to it, however actually accessing any part of it will be Bad™, unless explicitly initialized first.
using Standard;
using Containers;
using Attributes;
Map(String, String).Attribute(Const) x = [&] {
x = Map(String, String)();
x["ohai"] = "nub";
}();
Alternatively, a sort of lazy-evaluation could become a common idiom. Perhaps most types, most Standard types, will simply take a function object that will initialize them as a constructor argument after default-initializing as a construction option.
using Standard;
using Containers;
using Attributes;
Map(String, String).Attribute(Const) x([&] {
using Containers;
using Attributes;
Map(String, String).Attribute(Const) x([&] {
x["ohai"] = "nub";
});
});
Of course, this is pretty handy in C++ too. In fact, some of the lazy expression evaluation can be performed in C++, if you have a lib that supports it in combination with the new lambda functions. I think I'd rather have this than init lists.
No comments:
Post a Comment