ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/FreeBSDAdmin/IRC/foreach.hpp
Revision: 1262
Committed: 2010-03-20T20:07:58-07:00 (15 years, 3 months ago) by douglas
File size: 2428 byte(s)
Log Message:
Trout and the not yet useful beginnings of Smart ISON for ZNC.

File Contents

# User Rev Content
1 douglas 1262 // Foreach for STL
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7     /* Menes - C++ High-Level Utility Library
8     * Copyright (C) 2004 Jay Freeman (saurik)
9     */
10    
11     /*
12     * Redistribution and use in source and binary
13     * forms, with or without modification, are permitted
14     * provided that the following conditions are met:
15     *
16     * 1. Redistributions of source code must retain the
17     * above copyright notice, this list of conditions
18     * and the following disclaimer.
19     * 2. Redistributions in binary form must reproduce the
20     * above copyright notice, this list of conditions
21     * and the following disclaimer in the documentation
22     * and/or other materials provided with the
23     * distribution.
24     * 3. The name of the author may not be used to endorse
25     * or promote products derived from this software
26     * without specific prior written permission.
27     *
28     * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
29     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
30     * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
31     * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32     * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
33     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
34     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
35     * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
36     * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37     * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
38     * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
39     * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
40     * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41     * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42     */
43    
44     #ifndef _foreach_hpp_
45     #define _foreach_hpp_
46    
47     #define _forever for (;;)
48    
49     #define _forall(type, item, begin, end) \
50     if (size_t _index = 0); \
51     else for (type item(begin), _end(end); item != _end; ++item, ++_index)
52    
53     #define _rforall(type, item, begin, end) \
54     for (type item(end), _begin(begin); item != _begin && (--item, true); )
55    
56     #define _repeat(count) \
57     for (unsigned _index(0), _end(count); _index != _end; ++_index)
58    
59     #define _foreach(type, item, set) \
60     for (bool _stop(true); _stop; ) \
61     for (const type& _set = set; _stop; _stop = false) \
62     _forall (type::const_iterator, item, _set.begin(), _set.end())
63    
64     #define _rforeach(type, item, set) \
65     for (bool _stop(true); _stop; ) \
66     for (const type& _set = set; _stop; _stop = false) \
67     _rforall (type::const_iterator, item, _set.begin(), _set.end())
68    
69     #endif//_foreach_hpp_