2 bool optional params

spir denis.spir at gmail.com
Wed Nov 10 09:03:19 PST 2010


On Wed, 10 Nov 2010 11:03:27 -0500
"Steven Schveighoffer" <schveiguy at yahoo.com> wrote:

> On Wed, 10 Nov 2010 09:16:05 -0500, spir <denis.spir at gmail.com> wrote:
> 
> > On Wed, 10 Nov 2010 00:30:55 -0800
> > Jonathan M Davis <jmdavisProg at gmx.com> wrote:
> >
> >> On Tuesday 09 November 2010 23:55:26 spir wrote:
> >> > Hello,
> >> >
> >> > Is there a way for a func to hold 2 optional params of the same type?
> >> > 	void f(int p, bool b1=false, bool b2=false) {
> >> > 	    writefln("p=%s b1=%s b2=%s", p,b1,b2);
> >> > 	 }
> >> > Or is there a workaroud?
> 
> What about using a bitfield?
> 
> enum : ubyte
> {
>     b1 = 1;
>     b2 = 2;
> }
> 
> void f(int p, ubyte flags = 0)
> {
>     bool _b1 = flags & b1;
>     bool _b2 = flags & b2;
>     ...
> }
> 
> f(x, b1);
> f(x, b2);
> f(x, b1|b2);
> 
> -Steve

Oh, yes, thank you! That's a very good idea.


Denis
-- -- -- -- -- -- --
vit esse estrany ☣

spir.wikidot.com



More information about the Digitalmars-d-learn mailing list