summaryrefslogtreecommitdiff
path: root/libs/fusion/test/algorithm/find.cpp
blob: 83a86f1d9bafc5d1933e0ba67a8a41708600e305 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*=============================================================================
    Copyright (c) 2001-2011 Joel de Guzman

    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/detail/lightweight_test.hpp>
#include <boost/fusion/container/vector/vector.hpp>
#include <boost/fusion/adapted/mpl.hpp>
#include <boost/fusion/container/set/set.hpp>
#include <boost/fusion/container/map/map.hpp>
#include <boost/fusion/algorithm/query/find.hpp>
#include <boost/fusion/iterator/deref.hpp>
#include <boost/mpl/vector.hpp>
#include <string>

struct X
{
    operator int() const
    {
        return 12345;
    }
};
int
main()
{
    using namespace boost::fusion;
    using boost::mpl::identity;

    {
        typedef vector<int, char, int, double> seq_type;
        seq_type seq(12345, 'x', 678910, 3.36);

        std::cout << *boost::fusion::find<char>(seq) << std::endl;
        BOOST_TEST(*boost::fusion::find<char>(seq) == 'x');

        std::cout << *boost::fusion::find<int>(seq) << std::endl;
        BOOST_TEST(*boost::fusion::find<int>(seq) == 12345);

        std::cout << *boost::fusion::find<double>(seq) << std::endl;
        BOOST_TEST(*boost::fusion::find<double>(seq) == 3.36);

        BOOST_TEST(boost::fusion::find<bool>(seq) == boost::fusion::end(seq));
    }

    {
        typedef set<int, char, double> seq_type;
        seq_type seq(12345, 'x', 3.36);
        std::cout << *boost::fusion::find<char>(seq) << std::endl;
        BOOST_TEST(*boost::fusion::find<char>(seq) == 'x');
        BOOST_TEST(boost::fusion::find<bool>(seq) == boost::fusion::end(seq));
    }
    
    {
        typedef map<
            pair<int, char>
          , pair<double, std::string> > 
        map_type;
        
        map_type seq(
            make_pair<int>('X')
          , make_pair<double>("Men"));
        
        std::cout << *boost::fusion::find<int>(seq) << std::endl;
        std::cout << *boost::fusion::find<double>(seq) << std::endl;
        BOOST_TEST((*boost::fusion::find<int>(seq)).second == 'X');
        BOOST_TEST((*boost::fusion::find<double>(seq)).second == "Men");
        BOOST_TEST(boost::fusion::find<bool>(seq) == boost::fusion::end(seq));
    }

    {
        typedef boost::mpl::vector<int, char, X, double> mpl_vec;
        BOOST_TEST((*boost::fusion::find<X>(mpl_vec()) == 12345));
        BOOST_TEST(boost::fusion::find<bool>(mpl_vec()) == boost::fusion::end(mpl_vec()));
    }

    return boost::report_errors();
}