2 * Copyright (c) 1999-2000, Eric Moon.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions, and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 // Tools to manipulate STL set types.
39 // e.moon 27jul99 moved into cortex namespace
40 // e.moon 7may99 created
42 #ifndef __SET_TOOLS_H__
43 #define __SET_TOOLS_H__
45 #include "cortex_defs.h"
46 __BEGIN_CORTEX_NAMESPACE
48 // delete range of pointer values from set
50 void ptr_set_delete(iter begin
, iter end
) {
58 // delete range of pointer values from map
60 void ptr_map_delete(iter begin
, iter end
) {
63 delete (*begin
).second
;
68 // a simple equality-test functor for maps
69 template<class key
, class value
>
70 class map_value_equal_to
:
71 public std::binary_function
<std::pair
<key
,value
>, value
, bool> {
74 bool operator()(const std::pair
<key
,value
>& p
, const value
& v
) const {
79 //// a predicate functor adaptor for maps
81 //template<class key, class value>
82 //class map_value_predicate_t :
83 // public unary_function<pair<key,value>, bool> {
85 // const unary_function<const value, bool>& fn;
88 // map_value_predicate_t(const unary_function<const value, bool>& _fn) : fn(_fn) {}
89 // bool operator()(const std::pair<key,value>& p) const {
90 // return fn(p.second);
94 //template<class key, class value>
95 //inline map_value_predicate_t<key,value> map_value_predicate(
96 // const unary_function<const value, bool>& fn) {
97 // return map_value_predicate_t<key,value>(fn);
100 // copy values from a map subset
101 template<class input_iter
, class output_iter
>
102 void map_value_copy(input_iter begin
, input_iter end
, output_iter to
) {
103 while(begin
!= end
) {
104 *to
= (*begin
).second
;
110 // adapt a unary functor to a map (eek)
111 template <class pairT
, class opT
>
112 class unary_map_function_t
:
113 public std::unary_function
<typename
opT::argument_type
, typename
opT::result_type
> {
118 unary_map_function_t(const opT
& _f
) : f(_f
) {}
120 typename
opT::result_type
121 operator()(pairT
& p
) const {
126 template <class mapT
, class opT
>
127 inline unary_map_function_t
<typename
mapT::value_type
, opT
>
131 return unary_map_function_t
<typename
mapT::value_type
, opT
>(f
);
135 __END_CORTEX_NAMESPACE
136 #endif /* __SET_TOOLS_H__ */