DUAL FEATURE REQUEST: let "with" take a struct pointer and evaluate to its parameter
Bill Baxter
dnewsgroup at billbaxter.com
Thu Dec 20 19:46:28 PST 2007
downs wrote:
> The first part of the feature request is to allow "with" to take a pointer to a struct as a parameter.
>
> This is for the sake of internal consistency; since you can already call
> methods on a struct pointer as if it was dereferenced, it makes sense to
> also be able to use "with" on it.
+1 definitely. I think I've hit that one before too and it made me go
huh? wha?
By the way same sort of huh? wha? comes from trying to define a structs
opCmp to take a ref parameter.
> The second one arises from the following really cute idea ge0rg had in #d. Quote
>
>>> <Ge0rG> so you want 'auto foo = with(new myStruct) { bar = 23; baz = 42; ... }'?
>
> Things this breaks:
> * None; as usual with my feature requests, it only affects behavior that is currently illegal.
> What do you think?
I'm -1 on that.
This is really not so hard to do:
auto foo = new myStruct;
with (foo) { ... }
And the new syntax only saves typing "foo" once. Not worth it.
with() definitely could be a more useful beastie than it is, but I don't
think that's the way, and that would just get in the way of what I think
would be more useful growth opportunities like multiple with()
with(auto foo=myStruct.accesor(); auto bar=yourStruct.thingy) {
}
or non-scoped with(),
with big_object;
//like c++ "using", or alias big_object <.current namespace>;
or selective with().
with(something : member1,member2) {
member1 = 1; // gets something.member1
member2 = 2; // gets something.member2
member3 = 3; // error - didn't import member3
}
Or maybe those duties could be given to alias or import. I don't really
care which, but with seems like the current underachiever of the bunch,
so it seems like he could stand some more duties.
--bb
More information about the Digitalmars-d
mailing list