]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/functional/test/function_test.cpp
1 // ------------------------------------------------------------------------------
2 // Copyright (c) 2000 Cadenza New Zealand Ltd
3 // Distributed under the Boost Software License, Version 1.0. (See accompany-
4 // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 // ------------------------------------------------------------------------------
6 // Tests for the Boost functional.hpp header file
8 // Note that functional.hpp relies on partial specialisation to be
9 // effective. If your compiler lacks this feature, very few of the
10 // tests would compile, and so have been excluded from the test.
11 // ------------------------------------------------------------------------------
13 // ------------------------------------------------------------------------------
15 // Revision 1.3 2006/12/02 13:57:32 andreas_huber69
16 // Fixed license & copyright issues.
18 // From Mark Rodgers Fri Dec 1 12:59:14 2006
19 // X-Apparently-To: ahd6974-boostorg -at- yahoo.com via 68.142.206.160; Fri, 01 Dec 2006 12:59:41 -0800
20 // X-Originating-IP: [195.112.4.54]
21 // Return-Path: <mark.rodgers -at- cadenza.co.nz>
22 // Authentication-Results: mta550.mail.mud.yahoo.com from=cadenza.co.nz; domainkeys=neutral (no sig)
23 // Received: from 195.112.4.54 (EHLO smtp.nildram.co.uk) (195.112.4.54) by mta550.mail.mud.yahoo.com with SMTP; Fri, 01 Dec 2006 12:59:40 -0800
24 // Received: from snagglepuss.cadenza.co.nz (81-6-246-87.dyn.gotadsl.co.uk [81.6.246.87]) by smtp.nildram.co.uk (Postfix) with ESMTP id D32EA2B6D8C for <ahd6974-boostorg -at- yahoo.com>; Fri, 1 Dec 2006 20:59:35 +0000 (GMT)
25 // Received: from penfold.cadenza.co.nz ([192.168.55.56]) by snagglepuss.cadenza.co.nz with esmtp (Exim 4.63) (envelope-from <mark.rodgers -at- cadenza.co.nz>) id J9M4Y9-0009TO-9K for ahd6974-boostorg -at- yahoo.com; Fri, 01 Dec 2006 20:58:57 +0000
26 // Message-ID: <457097A2.1090305@cadenza.co.nz>
27 // Date: Fri, 01 Dec 2006 20:59:14 +0000
28 // From: "Mark Rodgers" <mark.rodgers -at- cadenza.co.nz>
29 // User-Agent: Thunderbird 1.5.0.8 (Macintosh/20061025)
31 // To: ahd6974-boostorg -at- yahoo.com [Edit - Delete]
32 // Subject: Re: [boost] Reminder: Need your permission to correct license & copyright issues
33 // References: <379990.36007.qm@web33507.mail.mud.yahoo.com>
34 // In-Reply-To: <379990.36007.qm@web33507.mail.mud.yahoo.com>
35 // Content-Type: text/plain; charset=ISO-8859-1; format=flowed
36 // Content-Transfer-Encoding: 7bit
37 // Content-Length: 812
40 // Sure that's fine. I'm happy for you to do 1, 2 and 3.
45 // Andreas Huber wrote:
48 // > Quite a while ago it was decided that every file that goes into the
49 // > 1.34 release of the Boost distribution (www.boost.org) needs uniform
50 // > license and copyright information. For more information please see:
52 // > <http://www.boost.org/more/license_info.html>
54 // > You are receiving this email because several files you contributed
55 // > lack such information or have an old license:
57 // > boost/functional/functional.hpp
58 // > boost/libs/functional/binders.html
59 // > boost/libs/functional/function_test.cpp
60 // > boost/libs/functional/function_traits.html
61 // > boost/libs/functional/index.html
62 // > boost/libs/functional/mem_fun.html
63 // > boost/libs/functional/negators.html
64 // > boost/libs/functional/ptr_fun.html
65 // > boost/people/mark_rodgers.htm
67 // > I therefore kindly ask you to grant the permission to do the
70 // > 1. For the files above that already have a license text (all except
71 // > mark_rodgers.htm), replace the license text with:
73 // > "Distributed under the Boost Software License, Version 1.0. (See
74 // > accompanying file LICENSE_1_0.txt or copy at
75 // > http://www.boost.org/LICENSE_1_0.txt)"
77 // > 2. For the file that does not yet have a license and copyright
78 // > (mark_rodgers.htm) add the same license text as under 1. and add the
79 // > following copyright:
81 // > "(c) Copyright Mark Rodgers 2000"
83 // > 3. (Optional) I would also want to convert all HTML files to conform
84 // > the HTML 4.01 Standard by running them through HTML Tidy, see
85 // > <http://tidy.sf.net>
87 // > It would be great if you could grant me permission to do 1 & 2 and
88 // > optionally also 3.
97 // Revision 1.2 2001/09/22 11:52:24 johnmaddock
98 // Intel C++ fixes: no void return types supported.
100 // Revision 1.1.1.1 2000/07/07 16:04:18 beman
101 // 1.16.1 initial CVS checkin
103 // Revision 1.3 2000/06/26 09:44:01 mark
104 // Updated following feedback from Jens Maurer.
106 // Revision 1.2 2000/05/17 08:31:45 mark
107 // Added extra tests now that function traits work correctly.
108 // For compilers with no support for partial specialisation,
109 // excluded tests that won't work.
111 // Revision 1.1 2000/05/07 09:14:41 mark
113 // ------------------------------------------------------------------------------
115 // To demonstrate what the boosted function object adapters do for
116 // you, try compiling with USE_STD defined. This will endeavour to
117 // use the standard function object adapters, but is likely to result
118 // in numerous errors due to the fact that you cannot have references
121 #include <functional>
124 #include <boost/functional.hpp>
137 Person ( const char * n
) : name ( n
) {}
139 const std :: string
& get_name () const { return name
; }
140 void print ( std :: ostream
& os
) const { os
<< name
<< " " ; }
141 void set_name ( const std :: string
& n
) { name
= n
; std :: cout
<< name
<< " " ; }
142 std :: string
clear_name () { std :: string ret
= name
; name
= "" ; return ret
; }
143 void do_something ( int ) const {}
145 bool is_fred () const { return name
== "Fred" ; }
153 bool is_equal ( const std :: string
& s1
, const std :: string
& s2
)
158 bool is_betty ( const std :: string
& s
)
163 void do_set_name ( Person
* p
, const std :: string
& name
)
168 void do_set_name_ref ( Person
& p
, const std :: string
& name
)
176 std :: vector
< Person
> v1
;
177 v1
. push_back ( "Fred" );
178 v1
. push_back ( "Wilma" );
179 v1
. push_back ( "Barney" );
180 v1
. push_back ( "Betty" );
182 const std :: vector
< Person
> cv1 ( v1
. begin (), v1
. end ());
184 std :: vector
< std :: string
> v2
;
185 v2
. push_back ( "Fred" );
186 v2
. push_back ( "Wilma" );
187 v2
. push_back ( "Barney" );
188 v2
. push_back ( "Betty" );
194 Person
wilma ( "Wilma" );
195 Person
barney ( "Barney" );
196 Person
betty ( "Betty" );
197 std :: vector
< Person
*> v3
;
199 v3
. push_back (& wilma
);
200 v3
. push_back (& barney
);
201 v3
. push_back (& betty
);
203 const std :: vector
< Person
*> cv3 ( v3
. begin (), v3
. end ());
204 std :: vector
< const Person
*> v3c ( v3
. begin (), v3
. end ());
206 std :: ostream
& os
= std :: cout
;
208 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(__ICL)
209 // unary_traits, unary_negate
210 std :: transform ( v2
. begin (), v2
. end (),
211 std :: ostream_iterator
< bool >( std :: cout
, " " ),
212 boost :: not1 ( is_betty
));
215 std :: transform ( v1
. begin (), v1
. end (),
216 std :: ostream_iterator
< bool >( std :: cout
, " " ),
217 boost :: not1 ( boost :: mem_fun_ref (& Person :: is_fred
)));
219 // binary_traits, binary_negate
221 std :: transform ( v2
. begin (), v2
. end (),
222 std :: ostream_iterator
< bool >( std :: cout
, " " ),
223 boost :: bind1st ( boost :: not2 ( is_equal
), "Betty" ));
226 std :: transform ( v2
. begin (), v2
. end (),
227 std :: ostream_iterator
< bool >( std :: cout
, " " ),
228 boost :: bind2nd ( boost :: not2 ( is_equal
), "Betty" ));
230 // pointer_to_unary_function
232 std :: transform ( v2
. begin (), v2
. end (),
233 std :: ostream_iterator
< bool >( std :: cout
, " " ),
234 boost :: not1 ( boost :: ptr_fun ( is_betty
)));
236 // binary_traits, bind1st, bind2nd
238 std :: transform ( v2
. begin (), v2
. end (),
239 std :: ostream_iterator
< bool >( std :: cout
, " " ),
240 boost :: bind1st ( is_equal
, "Betty" ));
243 std :: transform ( v2
. begin (), v2
. end (),
244 std :: ostream_iterator
< bool >( std :: cout
, " " ),
245 boost :: bind2nd ( is_equal
, "Betty" ));
247 // pointer_to_binary_function, bind1st
249 std :: for_each ( v2
. begin (), v2
. end (), boost :: bind1st ( boost :: ptr_fun ( do_set_name
), & person
));
252 std :: for_each ( v2
. begin (), v2
. end (), boost :: bind1st ( boost :: ptr_fun ( do_set_name_ref
), person
));
255 std :: for_each ( v2
. begin (), v2
. end (), boost :: bind1st ( boost :: ptr_fun ( do_set_name_ref
), r
));
259 std :: for_each ( v2
. begin (), v2
. end (), boost :: bind1st ( do_set_name
, & person
));
262 std :: for_each ( v2
. begin (), v2
. end (), boost :: bind1st ( do_set_name_ref
, person
));
265 std :: for_each ( v2
. begin (), v2
. end (), boost :: bind1st ( do_set_name_ref
, r
));
270 std :: transform ( v3
. begin (), v3
. end (),
271 std :: ostream_iterator
< std :: string
>( std :: cout
, " " ),
272 boost :: mem_fun (& Person :: get_name
));
275 std :: transform ( cv3
. begin (), cv3
. end (),
276 std :: ostream_iterator
< std :: string
>( std :: cout
, " " ),
277 boost :: mem_fun (& Person :: get_name
));
280 std :: transform ( v3c
. begin (), v3c
. end (),
281 std :: ostream_iterator
< std :: string
>( std :: cout
, " " ),
282 boost :: mem_fun (& Person :: get_name
));
284 // const_mem_fun_ref_t
286 std :: transform ( v1
. begin (), v1
. end (),
287 std :: ostream_iterator
< std :: string
>( std :: cout
, " " ),
288 boost :: mem_fun_ref (& Person :: get_name
));
291 std :: transform ( cv1
. begin (), cv1
. end (),
292 std :: ostream_iterator
< std :: string
>( std :: cout
, " " ),
293 boost :: mem_fun_ref (& Person :: get_name
));
295 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
296 // const_mem_fun1_t, bind2nd
298 std :: for_each ( v3
. begin (), v3
. end (), boost :: bind2nd ( boost :: mem_fun (& Person :: print
), std :: cout
));
301 std :: for_each ( v3
. begin (), v3
. end (), boost :: bind2nd ( boost :: mem_fun (& Person :: print
), os
));
303 // const_mem_fun1_ref_t, bind2nd
305 std :: for_each ( v1
. begin (), v1
. end (), boost :: bind2nd ( boost :: mem_fun_ref (& Person :: print
), std :: cout
));
308 std :: for_each ( v1
. begin (), v1
. end (), boost :: bind2nd ( boost :: mem_fun_ref (& Person :: print
), os
));
310 // mem_fun1_t, bind1st
312 std :: for_each ( v2
. begin (), v2
. end (), boost :: bind1st ( boost :: mem_fun (& Person :: set_name
), & person
));
314 // mem_fun1_ref_t, bind1st
316 std :: for_each ( v2
. begin (), v2
. end (), boost :: bind1st ( boost :: mem_fun_ref (& Person :: set_name
), person
));
319 std :: for_each ( v2
. begin (), v2
. end (), boost :: bind1st ( boost :: mem_fun_ref (& Person :: set_name
), r
));
324 std :: transform ( v3
. begin (), v3
. end (), std :: ostream_iterator
< std :: string
>( std :: cout
, " " ),
325 boost :: mem_fun (& Person :: clear_name
));
329 std :: transform ( v1
. begin (), v1
. end (), std :: ostream_iterator
< std :: string
>( std :: cout
, " " ),
330 boost :: mem_fun_ref (& Person :: clear_name
));