File: includes.cc

package info (click to toggle)
c%2B%2B-annotations 12.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 13,044 kB
  • sloc: cpp: 24,337; makefile: 1,517; ansic: 165; sh: 121; perl: 90
file content (62 lines) | stat: -rw-r--r-- 2,167 bytes parent folder | download | duplicates (3)
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
    #include <algorithm>
    #include <string>
    #include <cstring>
    #include <iostream>
    using namespace std;

    class CaseString
    {
        public:
            bool operator()(string const &first,
                            string const &second) const
            {
                return !strcasecmp(first.c_str(), second.c_str());
            }
    };
    int main()
    {
        string first1[] =
            {
                "alpha", "bravo", "charley", "delta",  "echo",
                "foxtrot", "golf", "hotel"
            };
        string first2[] =
            {
                "Alpha", "bravo", "Charley", "delta",  "Echo",
                "foxtrot", "Golf", "hotel"
            };
        string second[] =
            {
                "charley", "foxtrot", "hotel"
            };
        size_t n = sizeof(first1) / sizeof(string);

        cout << "The elements of `second' are " <<
            (includes(first1, first1 + n, second, second + 3) ? "" : "not")
            << " contained in the first sequence:\n"
               "second is a subset of first1\n";

        cout << "The elements of `first1' are " <<
            (includes(second, second + 3, first1, first1 + n) ? "" : "not")
            << " contained in the second sequence\n";

        cout << "The elements of `second' are " <<
            (includes(first2, first2 + n, second, second + 3) ? "" : "not")
            << " contained in the first2 sequence\n";

        cout << "Using case-insensitive comparison,\n"
            "the elements of `second' are "
            <<
            (includes(first2, first2 + n, second, second + 3, CaseString{}) ?
                "" : "not")
            << " contained in the first2 sequence\n";
    }
    /*
        Displays:
            The elements of `second' are  contained in the first sequence:
            second is a subset of first1
            The elements of `first1' are not contained in the second sequence
            The elements of `second' are not contained in the first2 sequence
            Using case-insensitive comparison,
            the elements of `second' are  contained in the first2 sequence
    */