adjust test spec: C++11 does indeed pass ref parameters even through function objects

This is a notable difference to the boost or tr1-function objects
we used up to now. Thus the behavour is now straight forward without
any exception. If the function takes an argument by reference,
this is replicated through bind and function expressions
This commit is contained in:
Fischlurch 2014-05-10 02:14:38 +02:00
parent 4acb7de682
commit a421cf45de
2 changed files with 41 additions and 32 deletions

View file

@ -1386,20 +1386,21 @@ out: :50:49:48:47:46:45:44:43:42:41
out: :60
out: :70
out: :80:59:58:57:56:55:54:53:52:51
out: :80$
out: :90:69:68:67:66:65:64:63:62:61
out: :100$
out: ---:assign_to_var
out: :60:99:137:174:210:245:279:312:344:375
out: :435:474:512:549:585:620:654:687:719:750
out: :810:789:788:787:786:785:784:783:782:781
out: sum=750
out: :60:99:137:174:210:245:279:312:344:375
out: :435:474:512:549:585:620:654:687:719:750
out: :810:789:788:787:786:785:784:783:782:781
out: sum=750
out: :60
out: :120
out: :90:149:207:264:320:375:429:482:534:585
out: :675:734:792:849:905:960:1014:1067:1119:1170
out: :1260:1319:1377:1434:1490:1545:1599:1652:1704:1755
out: sum=1755
out: :90:149:207:264:320:375:429:482:534:585
out: :675:734:792:849:905:960:1014:1067:1119:1170
out: :1260:1319:1377:1434:1490:1545:1599:1652:1704:1755
out: sum=1755
out: :90
out: :180
out: sum=120
out: :270
out: sum=270
out: ---:assign_to_input
out: :20:19:18:17:16:15:14:13:12:11
out: :30:29:28:27:26:25:24:23:22:21
@ -1408,20 +1409,21 @@ out: :50:49:48:47:46:45:44:43:42:41
out: :60
out: :70
out: :80:59:58:57:56:55:54:53:52:51
out: :80$
out: :90:69:68:67:66:65:64:63:62:61
out: :100$
out: ---:assign_to_var
out: :60:99:137:174:210:245:279:312:344:375
out: :435:474:512:549:585:620:654:687:719:750
out: :810:789:788:787:786:785:784:783:782:781
out: sum=750
out: :60:99:137:174:210:245:279:312:344:375
out: :435:474:512:549:585:620:654:687:719:750
out: :810:789:788:787:786:785:784:783:782:781
out: sum=750
out: :60
out: :120
out: :90:149:207:264:320:375:429:482:534:585
out: :675:734:792:849:905:960:1014:1067:1119:1170
out: :1260:1319:1377:1434:1490:1545:1599:1652:1704:1755
out: sum=1755
out: :90:149:207:264:320:375:429:482:534:585
out: :675:734:792:849:905:960:1014:1067:1119:1170
out: :1260:1319:1377:1434:1490:1545:1599:1652:1704:1755
out: sum=1755
out: :90
out: :180
out: sum=120
out: :270
out: sum=270
out: ---:wrapped_container_passing
out: :10:9:8:7:6:5:4:3:2:1
out: :-20:-21:-22:-23:-24:-25:-26:-27:-28:-29

View file

@ -156,7 +156,7 @@ namespace test {
CHECK (int(NUM_ELMS) ==container[0]);
check_ref_argument_bind (iterator);
CHECK (60+int(NUM_ELMS) ==container[0]);
CHECK (90+int(NUM_ELMS) ==container[0]);
// changes got propagated through the iterator
check_wrapped_container_passing(container);
@ -233,7 +233,11 @@ namespace test {
/** @test under some circumstances, it is even possible
* to take a ref to the data in the input sequence,
* or to a summation variable.
* or to a summation variable. In the example performed here,
* the function to be applied takes the 3rd argument by reference
* and assigns the sum of first and second argument to this parameter.
* If we us a bind variable at that position, we end up assigning
* by reference to the values contained in the collection.
* @note in case of invoking this test with a Lumiera Forward Iterator,
* the changes go through to the original container, in spite of
* passing the iterator by value. This behaviour is correct, as
@ -256,13 +260,16 @@ namespace test {
has_any (coll, function2, 5, 5, _1 ); _NL_
has_any (coll, &function2, 5, 5, _1 ); _NL_
// note: when using a function object,
// instead of directly using a binder,
// the pass-by reference doesn't work
// note: in C++11, the reference parameters are passed through
// even when wrapping the function or function pointer into a function object,
for_each (coll,fun2, 5, 5, _1 ); _NL_
and_all (coll, fun2, 5, 5, _1 ); _NL_
has_any (coll, fun2, 5, 5, _1 ); _NL_
// at that point we have added 9 * (5+5) to the value at position zero.
// (note that the has_any only evaluates the function once)
// the following test assigns the sum via the ref argument to a local variable.
int sum=0;
ANNOUNCE (assign_to_var);
for_each (coll, function2, -10, _1, ref(sum) ); _NL_
@ -417,7 +424,7 @@ namespace test {
}
/** @test passing the collection to be iterated in various ways
/** @test pass the collection to be iterated in various ways
* - anonymous temporary
* - smart pointer
* - pointer
@ -458,12 +465,12 @@ namespace test {
CHECK (-2*int(NUM_ELMS) == counter);
CHECK (bySmartPtr->back() == counter+1);
// passing by pointer is also possible
// passing the container by pointer is also possible
const VecI * const passByConstPointer (&coll);
for_each (passByConstPointer, _1_ = var(counter)-- );
SHOW_CONTAINER
// ...and influences the original container
// ...and does indeed influence the original container
}
};