Tango BitArray Initialization
Colin Huang
colin.hwong at gmail.com
Mon Feb 12 00:43:30 PST 2007
Sean Kelly Wrote:
> Colin Huang wrote:
> > Sean Kelly Wrote:
> >
> >> I don't think this is legal in D. In fact, the syntax is a huge problem
> >> in C++ because the parser often can't distinguish between a variable
> >> decl and a function prototype, and function prototypes take precedence.
> >
> > Yeah, that got me really confused when I first started learning C++
> >
> >> It may be uglier, but:
> >>
> >> BitArray b = BitArray( 1, 0, 1 );
> >>
> >> is better than:
> >>
> >> BitArray b( 1, 0, 1 );
> >>
> >> I only wish that the syntax worked for all stack variables. ie.
> >>
> >> int x = int( 1 );
> >
> > Why is this useful? Isn't "int x = 1" enough?
>
> Templates. It still isn't perfect because classes can't be initialized
> this way, but:
>
> void buildAndCall(T, Call, Params...)( Call fn, Params p )
> {
> T val = T( p );
> fn( val );
> }
>
> Probably a bad example, but you get the idea. It's nice to be able to
> initialize everything using the same syntax. I'd almost suggest:
>
> scope T val = new T( p );
>
> as the "universal" scoped declaration syntax, but the presence of the
> 'new' is not terribly ideal, even though it should work for classes as well.
>
Ah, that makes sense. Should've thought of it :)
Colin
More information about the Digitalmars-d-learn
mailing list