File: querying2.cpp

package info (click to toggle)
boost1.88 1.88.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 576,932 kB
  • sloc: cpp: 4,149,234; xml: 136,789; ansic: 35,092; python: 33,910; asm: 5,698; sh: 4,604; ada: 1,681; makefile: 1,633; pascal: 1,139; perl: 1,124; sql: 640; yacc: 478; ruby: 271; java: 77; lisp: 24; csh: 6
file content (85 lines) | stat: -rw-r--r-- 2,980 bytes parent folder | download | duplicates (14)
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
80
81
82
83
84
85
/*=============================================================================
    Copyright (c) 2005-2007 Dan Marsden
    Copyright (c) 2005-2007 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/phoenix/core.hpp>
#include <boost/phoenix/stl/algorithm/querying.hpp>
#include <boost/detail/lightweight_test.hpp>

#include <boost/range.hpp>

#include <functional>

namespace
{
    void includes_test()
    {
        using boost::phoenix::includes;
        using boost::phoenix::arg_names::arg1;
        using boost::phoenix::arg_names::arg2;
        int array[] = {1,2,3};
        int array2[] = {1,2};
        BOOST_TEST(includes(arg1, arg2)(array, array2));
        boost::iterator_range<int*> rng(array + 1, array + 3);
        BOOST_TEST(!includes(arg1, arg2)(rng, array2));

        int array3[] = {3,2,1};
        int array4[] = {2,1};
        BOOST_TEST(boost::phoenix::includes(arg1, arg2, std::greater<int>())(array3, array4));
        boost::iterator_range<int*> rng2(array3, array3 + 2);
        BOOST_TEST(!boost::phoenix::includes(arg1, arg2, std::greater<int>())(rng2, array4));
        return;
    }

    void min_element_test()
    {
        using boost::phoenix::min_element;
        using boost::phoenix::arg_names::arg1;
        int array[] = {1,3,2};
        BOOST_TEST(min_element(arg1)(array) == array);
        BOOST_TEST(boost::phoenix::min_element(arg1, std::greater<int>())(array) == array + 1);
        return;
    }

    void max_element_test()
    {
        using boost::phoenix::max_element;
        using boost::phoenix::arg_names::arg1;
        int array[] = {1,3,2};
        BOOST_TEST(max_element(arg1)(array) == array + 1);
        BOOST_TEST(boost::phoenix::max_element(arg1, std::greater<int>())(array) == array);
        return;
    }

    void lexicographical_compare_test()
    {
        using boost::phoenix::lexicographical_compare;
        using boost::phoenix::arg_names::arg1;
        using boost::phoenix::arg_names::arg2;
        int array[] = {1,2,3};
        int array2[] = {1,2,4};

        BOOST_TEST(lexicographical_compare(arg1, arg2)(array, array2));
        BOOST_TEST(!lexicographical_compare(arg1, arg2)(array2, array));
        BOOST_TEST(!lexicographical_compare(arg1, arg2)(array, array));

        BOOST_TEST(!boost::phoenix::lexicographical_compare(arg1, arg2, std::greater<int>())(array, array2));
        BOOST_TEST(boost::phoenix::lexicographical_compare(arg1, arg2, std::greater<int>())(array2, array));
        BOOST_TEST(!boost::phoenix::lexicographical_compare(arg1, arg2, std::greater<int>())(array, array));

        return;
    }
}

int main()
{
    includes_test();
    min_element_test();
    max_element_test();
    lexicographical_compare_test();
    return boost::report_errors();
}