Hi All

This is a feature request. To explain, lets say I want to create a
TriBool type, like so:

enum TriBool { False, True, Unknown };

I now want to implement operator&&. I want operator&& to short
circuit, i.e. if the first argument is False the second argument
shouldn't be evaluated.

So I'll make operator&& take a function object for it's second
argument, like so:

TriBool operator&&
(
  TriBool x,
  const std::function<TriBool()>& y
)
{
  if (x == False) { return False; }
  else
  {
    TriBool y_ = y();
    if (x == True) { return y_; }
    else if (y_ == False) { return False; }
    else { return Unknown; }
  }
}

This way if I have:

#define DELAY(x) [&]{ return x; }

TriBool f();
TriBool g();

I can do:

f() && DELAY(g())

and hence have short circuit evaluation.

However, what I'd like to have is just "f() && g()". It would be good
to be able to give the second argument an attribute which basically
wraps any argument passed to it with "DELAY()". Is this possible, or
has it already been done?

Regards,

Clinton

Reply via email to