Home | History | Annotate | Download | only in set
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <set>
     11 
     12 // class set
     13 
     14 //       iterator find(const key_type& k);
     15 // const_iterator find(const key_type& k) const;
     16 
     17 #include <set>
     18 #include <cassert>
     19 
     20 int main()
     21 {
     22     typedef int V;
     23     typedef std::set<int> M;
     24     {
     25         typedef M::iterator R;
     26         V ar[] =
     27         {
     28             5,
     29             6,
     30             7,
     31             8,
     32             9,
     33             10,
     34             11,
     35             12
     36         };
     37         M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
     38         R r = m.find(5);
     39         assert(r == m.begin());
     40         r = m.find(6);
     41         assert(r == next(m.begin()));
     42         r = m.find(7);
     43         assert(r == next(m.begin(), 2));
     44         r = m.find(8);
     45         assert(r == next(m.begin(), 3));
     46         r = m.find(9);
     47         assert(r == next(m.begin(), 4));
     48         r = m.find(10);
     49         assert(r == next(m.begin(), 5));
     50         r = m.find(11);
     51         assert(r == next(m.begin(), 6));
     52         r = m.find(12);
     53         assert(r == next(m.begin(), 7));
     54         r = m.find(4);
     55         assert(r == next(m.begin(), 8));
     56     }
     57     {
     58         typedef M::const_iterator R;
     59         V ar[] =
     60         {
     61             5,
     62             6,
     63             7,
     64             8,
     65             9,
     66             10,
     67             11,
     68             12
     69         };
     70         const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
     71         R r = m.find(5);
     72         assert(r == m.begin());
     73         r = m.find(6);
     74         assert(r == next(m.begin()));
     75         r = m.find(7);
     76         assert(r == next(m.begin(), 2));
     77         r = m.find(8);
     78         assert(r == next(m.begin(), 3));
     79         r = m.find(9);
     80         assert(r == next(m.begin(), 4));
     81         r = m.find(10);
     82         assert(r == next(m.begin(), 5));
     83         r = m.find(11);
     84         assert(r == next(m.begin(), 6));
     85         r = m.find(12);
     86         assert(r == next(m.begin(), 7));
     87         r = m.find(4);
     88         assert(r == next(m.begin(), 8));
     89     }
     90 }
     91