This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Feature request: Attribute to delay evaluation of function argument


On Sun, 2012-11-04 at 18:08 +1100, Clinton Mead wrote:
> Hi Oleg
> 
> Could you explain how you get around the following:
> 
> (1) Doesn't the non-overloaded operator&& return 'bool', not
> 'TriBool'? 

Yes, by default it takes bool on both sides and returns bool.

> How can it be made to return 'TriBool'?

By overloading it.

> (2) How can one prevent losing information by converting to 'bool'?

This is difficult to answer without knowing more about the use cases
that you have in mind.  For example if you want to be able to write
something like ...

tribool x = ...; tribool y = ...;
tribool z = x && y;

you'll have to overload operator &&.
Then, if you want to be able to do stuff like ...

tribool x = ...; tribool y = ...;
tribool z = x && y;
if (z) { ... }

or inherently...
if (x && y) { ... }

you'll have to provide explicit operator bool in the class tribool.

> (3) How can technique be applied more generally to functions not named
> '&&' or '||' in such a way that the suggested feature would allow?

You mean, to allow short-circuit evaluation for normal functions?
If so, how would that look in practice (use case example)?


Cheers,
Oleg


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]