summaryrefslogtreecommitdiff
path: root/libs/phoenix/test/function/lazy_list3_tests.cpp
blob: 9e4bc6d0dda9a8c83a2d575392986bb20b2e3d77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
////////////////////////////////////////////////////////////////////////////
// lazy_list3_tests.cpp
//
// more tests on list<T>
//
////////////////////////////////////////////////////////////////////////////
/*=============================================================================
    Copyright (c) 2000-2003 Brian McNamara and Yannis Smaragdakis
    Copyright (c) 2001-2007 Joel de Guzman
    Copyright (c) 2015 John Fletcher

    Distributed under the Boost Software License, Version 1.0. (See accompanying
    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/

#include <boost/phoenix/core/limits.hpp>

#include <boost/detail/lightweight_test.hpp>
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/function/lazy_prelude.hpp>


int main()
{
    namespace phx = boost::phoenix;
    //using boost::phoenix::arg_names::arg1;
    //using boost::phoenix::arg_names::arg2;
    using namespace phx;

    list<int> l    = enum_from(2);
    list<int> ll   = take(4,l);
    list<int> lll  = take(12,l);
    list<int> l2   = enum_from_to(2,10);
    list<int> ll2  = take(4,l2);
    list<int> lll2 = take(12,l2);
    list<int> evens = filter(even,l);
    list<int> odds  = filter(odd,l);
    list<int> even4 = take(4,evens)();
    list<int> odd4  = take(4,odds)();
    list<int> itersome = take(4,iterate(dec,1))();
    list<int> repeatsome = take(4,repeat(1))();
    
    BOOST_TEST(last(ll)()   == 5);
    BOOST_TEST(last(lll)()  == 13);
    BOOST_TEST(last(ll2)()  == 5);
    BOOST_TEST(last(lll2)() == 10);
    BOOST_TEST(length(lll2)() == 9);
    BOOST_TEST(at_(even4,3)() == 8);
    BOOST_TEST(at_(odd4,2)()  == 7);
    BOOST_TEST(at_(itersome,3)()   == -3);
    BOOST_TEST(at_(repeatsome,3)() == 1);

    return boost::report_errors();
}