Здравствуйте, Draqon, Вы писали:
D>Есть функции foo() и bar().
D>Требуется выполнить обе и вернуть результат такой же, как foo() && bar().
D>Как уважаемый Аll посоветует это записать, чтобы достичь оптимума компактности и читабельности?
D>Пока придумалось такое:
D>D>return foo() ? bar() : (bar(), false);
D>
Придумалось такое

:
struct MyANDProxy
{
MyANDProxy( bool bResult ) : m_bResult( bResult )
{
}
bool operator > ( bool bRightResult )
{
return m_bResult && bRightResult;
}
bool m_bResult;
};
struct MyAND
{
};
MyANDProxy operator < ( bool bLeftResult, MyAND and )
{
return MyANDProxy( bLeftResult );
}
MyAND and;
Использование:
return foo() <and> bar();
П.С. Просьба ногами не бить — это лишь демонстрация концепта, нагло сдертая из статьи в кудже.
Здравствуйте, Draqon, Вы писали:
return foo() >>! bar();
A>Полностью согласен.
A>Как писал Francis Glassborow в CVu 17.6:
FG>>I contend that anyone who believes that the following code is safe and guaranteed to
FG>>output 5 is not qualified to write guidelines for use of C in safety critical contexts.
FG>>FG>>#include <stdio.h>
FG>>int main(){
FG>> int i = 2;
FG>> int j = (i++) + (i++); /* A */
FG>> printf("%d", j);
FG>> return 0;
FG>>}
FG>>
Грубо высказался товарищщ. Надо было "is not qualified to write guidelines to those who writes guidelines...{n раз} for use of C in safety critical contexts.
Здравствуйте, Draqon, Вы писали:
D>Здравствуйте, ned, Вы писали:
ned>>Да. Для обычных (не логических) операций всегда вычисляются оба операнда.
D>А где это "всегда" в стандарте написано, не подскажете?
Да пожалста...

5.14 Logical AND operator [expr.log.and]
logical-and-expression:
inclusive-or-expression
logical-and-expression && inclusive-or-expression
1 The && operator groups left-to-right. The operands are both implicitly converted to type bool (clause 4).
The result is true if both operands are true and false otherwise. Unlike &, && guarantees left-to-right
evaluation: the second operand is not evaluated if the first operand is false.
Упс, сорри, забыл страницу перелистнуть и ответил
Здравствуйте, Olivan, Вы писали:
O>Здравствуйте, Draqon, Вы писали:
O>O> return foo() >>! bar();
O>
O>
Гыы, круто)