mirror of
https://github.com/boostorg/yap.git
synced 2026-02-23 16:22:09 +00:00
Test return of reference values from expression evaluations.
This commit is contained in:
51
sketch.cpp
51
sketch.cpp
@@ -1412,6 +1412,55 @@ void call_expr ()
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
namespace reference_returning {
|
||||
|
||||
struct number
|
||||
{
|
||||
double value;
|
||||
};
|
||||
|
||||
number const the_result{13.0};
|
||||
|
||||
// User-defined binary-plus! With weird reference semantics!
|
||||
template <typename A, typename B>
|
||||
inline number const & eval_plus (A a, B b)
|
||||
{ return the_result; }
|
||||
|
||||
}
|
||||
|
||||
void reference_returns ()
|
||||
{
|
||||
term<reference_returning::number> unity = {{1.0}};
|
||||
auto expr = unity + reference_returning::number{1.0};
|
||||
|
||||
// TODO: This has to fail due to the general implicit declaration rules
|
||||
// (see [conv] 3-6). This needs to be noted in docs.
|
||||
#if 0
|
||||
{
|
||||
reference_returning::number const & n = expr;
|
||||
if (&n == &reference_returning::the_result)
|
||||
std::cout << "Got the_result.\n";
|
||||
else
|
||||
std::cout << "FAIL\n";
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
reference_returning::number const & n = evaluate(expr);
|
||||
if (&n == &reference_returning::the_result)
|
||||
std::cout << "Got the_result.\n";
|
||||
else
|
||||
std::cout << "FAIL\n";
|
||||
}
|
||||
|
||||
static_assert(
|
||||
std::is_same_v<
|
||||
decltype(evaluate(expr)),
|
||||
reference_returning::number const &
|
||||
>
|
||||
);
|
||||
}
|
||||
|
||||
int main ()
|
||||
{
|
||||
term_plus_x();
|
||||
@@ -1432,6 +1481,8 @@ int main ()
|
||||
|
||||
call_expr();
|
||||
|
||||
reference_returns();
|
||||
|
||||
#if 0 // TODO
|
||||
{
|
||||
bp17::terminal<double> unity{1.0};
|
||||
|
||||
Reference in New Issue
Block a user