add special for-each handling for Lumiera Forward Iterator
This commit is contained in:
parent
d2f24504bd
commit
bf48ebc272
2 changed files with 170 additions and 11 deletions
|
|
@ -938,6 +938,101 @@ return: 0
|
|||
END
|
||||
|
||||
|
||||
TEST "for-each operations" UtilForeach_test 10 <<END
|
||||
out: ---:check_foreach_plain
|
||||
out: :10:9:8:7:6:5:4:3:2:1
|
||||
out: :10$
|
||||
out: ---:check_foreach_plain
|
||||
out: :10:9:8:7:6:5:4:3:2:1
|
||||
out: :10$
|
||||
out: ---:check_foreach_bind
|
||||
out: :20:19:18:17:16:15:14:13:12:11
|
||||
out: :20$
|
||||
out: :20:18:16:14:12:10:8:6:4:2
|
||||
out: :20$
|
||||
out: ---:check_foreach_bind
|
||||
out: :20:19:18:17:16:15:14:13:12:11
|
||||
out: :20$
|
||||
out: :20:18:16:14:12:10:8:6:4:2
|
||||
out: :20$
|
||||
out: ---:check_foreach_bind_const
|
||||
out: :20:19:18:17:16:15:14:13:12:11
|
||||
out: :20$
|
||||
out: :20:18:16:14:12:10:8:6:4:2
|
||||
out: :20$
|
||||
out: :20:38:54:68:80:90:98:104:108:110
|
||||
out: :130:148:164:178:190:200:208:214:218:220
|
||||
out: :240
|
||||
out: ---:check_foreach_memFun
|
||||
out: :10:19:27:34:40:45:49:52:54:55
|
||||
out: :10$
|
||||
out: :10:19:27:34:40:45:49:52:54:55
|
||||
out: :65:74:82:89:95:100:104:107:109:110
|
||||
out: :120
|
||||
out: sum=120
|
||||
out: ---:check_foreach_memFun
|
||||
out: :10:19:27:34:40:45:49:52:54:55
|
||||
out: :10$
|
||||
out: :10:19:27:34:40:45:49:52:54:55
|
||||
out: :65:74:82:89:95:100:104:107:109:110
|
||||
out: :120
|
||||
out: sum=120
|
||||
out: ---:check_foreach_lambda
|
||||
out: ---:check_existence_quant
|
||||
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
|
||||
out: :40:39:38:37:36:35:34:33:32:31
|
||||
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: ---: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: :180
|
||||
out: sum=120
|
||||
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
|
||||
out: :40:39:38:37:36:35:34:33:32:31
|
||||
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: ---: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: :180
|
||||
out: sum=120
|
||||
out: ---:check_invoke_on_each
|
||||
out: :0:1:2:3:4:5
|
||||
out: :0$
|
||||
out: :0:1$
|
||||
out: :0:1:2:3:4:5
|
||||
out: :0$
|
||||
out: :0:1$
|
||||
END
|
||||
|
||||
|
||||
TEST "VectorTransfer_test" VectorTransfer_test <<END
|
||||
return: 0
|
||||
END
|
||||
|
|
|
|||
|
|
@ -51,6 +51,42 @@ using namespace boost::lambda;
|
|||
namespace util {
|
||||
///////////////////////////////////////////////////////////////////////////TODO: Implementation draft
|
||||
|
||||
template <typename IT
|
||||
,typename FUN
|
||||
>
|
||||
inline typename enable_if< can_IterForEach<IT>,
|
||||
FUN >::type
|
||||
for_each (IT& ii, FUN doIt)
|
||||
{
|
||||
return std::for_each (ii, IT(), doIt);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename IT
|
||||
,typename FUN
|
||||
>
|
||||
inline typename enable_if< can_IterForEach<IT>,
|
||||
bool >::type
|
||||
and_all (IT& ii, FUN predicate)
|
||||
{
|
||||
return and_all (ii, IT(), predicate);
|
||||
}
|
||||
|
||||
|
||||
template <typename IT
|
||||
,typename FUN
|
||||
>
|
||||
inline typename enable_if< can_IterForEach<IT>,
|
||||
bool >::type
|
||||
has_any (IT& ii, FUN predicate)
|
||||
{
|
||||
return has_any (ii, IT(), predicate);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
using std::tr1::bind;
|
||||
|
||||
template < typename CON, typename FUN
|
||||
|
|
@ -245,21 +281,30 @@ namespace test {
|
|||
RangeI iterator(container.begin(), container.end());
|
||||
|
||||
check_foreach_plain (container);
|
||||
// check_foreach_plain (iterator);
|
||||
check_foreach_plain (iterator);
|
||||
|
||||
check_foreach_bind (container);
|
||||
// check_foreach_bind (iterator);
|
||||
check_foreach_bind (iterator);
|
||||
|
||||
check_foreach_bind_const (container);
|
||||
|
||||
check_foreach_memFun (container);
|
||||
// check_foreach_memFun (iterator);
|
||||
check_foreach_memFun (iterator);
|
||||
|
||||
check_foreach_lambda (container);
|
||||
// check_foreach_lambda (iterator);
|
||||
check_foreach_lambda (iterator);
|
||||
|
||||
check_existence_quant (container);
|
||||
// check_existence_quant (iterator);
|
||||
check_existence_quant (iterator);
|
||||
|
||||
ASSERT (int(NUM_ELMS) ==container[0]);
|
||||
|
||||
check_ref_argument_bind (container);
|
||||
ASSERT (int(NUM_ELMS) ==container[0]);
|
||||
|
||||
check_ref_argument_bind (iterator);
|
||||
ASSERT (60+int(NUM_ELMS) ==container[0]);
|
||||
// changes got propagated through the iterator
|
||||
|
||||
check_invoke_on_each ();
|
||||
}
|
||||
|
|
@ -299,7 +344,6 @@ namespace test {
|
|||
{
|
||||
ANNOUNCE (check_foreach_bind);
|
||||
function<bool(int,int)> fun1(function1);
|
||||
function<bool(int,int,int)> fun2(function2);
|
||||
|
||||
for_each (coll, function1, 10, _1 ); _NL_
|
||||
for_each (coll, &function1,10, _1 ); _NL_
|
||||
|
|
@ -329,19 +373,39 @@ namespace test {
|
|||
// for_each (coll, function1, 10, 20, _1 );
|
||||
// for_each (coll, function1, _1, _2 );
|
||||
// for_each (coll, function1, 10 );
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/** @test under some circumstances, it is even possible
|
||||
* to take a ref to the data in the input sequence,
|
||||
* or to a summation variable.
|
||||
* @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
|
||||
* an iterator is an reference-like object
|
||||
*
|
||||
* */
|
||||
template<typename CO>
|
||||
void
|
||||
check_ref_argument_bind (CO coll)
|
||||
{
|
||||
ANNOUNCE (assign_to_input);
|
||||
function<bool(int,int,int)> fun2(function2);
|
||||
|
||||
for_each (coll, function2, 5, 5, _1 ); _NL_
|
||||
for_each (coll, &function2,5, 5, _1 ); _NL_
|
||||
for_each (coll, fun2, 5, 5, _1 ); _NL_
|
||||
|
||||
and_all (coll, function2, 5, 5, _1 ); _NL_
|
||||
and_all (coll, &function2, 5, 5, _1 ); _NL_
|
||||
and_all (coll, fun2, 5, 5, _1 ); _NL_
|
||||
|
||||
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
|
||||
for_each (coll,fun2, 5, 5, _1 ); _NL_
|
||||
and_all (coll, fun2, 5, 5, _1 ); _NL_
|
||||
has_any (coll, fun2, 5, 5, _1 ); _NL_
|
||||
|
||||
int sum=0;
|
||||
|
|
@ -435,7 +499,7 @@ namespace test {
|
|||
|
||||
for_each (coll, var(sum) += _1_ );
|
||||
|
||||
ASSERT (sum == NUM_ELMS/2 * (NUM_ELMS+1));
|
||||
ASSERT (sum == (NUM_ELMS+1) * NUM_ELMS/2);
|
||||
|
||||
ASSERT (!and_all (coll, _1_ - 1 ));
|
||||
ASSERT ( has_any (coll, _1_ + 1 ));
|
||||
|
|
|
|||
Loading…
Reference in a new issue