Compare commits

...

86 Commits

Author SHA1 Message Date
nobody
ee6a0e5dc3 This commit was manufactured by cvs2svn to create tag
'Version_1_33_1'.

[SVN r31916]
2005-12-05 14:04:06 +00:00
Douglas Gregor
6417c3a7a2 Clean up a whole lot of bad links
[SVN r31851]
2005-12-01 04:52:04 +00:00
nobody
232bb39198 This commit was manufactured by cvs2svn to create branch 'RC_1_33_0'.
[SVN r30300]
2005-07-28 18:22:24 +00:00
Victor A. Wagner Jr.
2a21f7df2c Added - an example of using boost::cref
[SVN r29376]
2005-06-02 15:29:01 +00:00
Peter Dimov
9cfe194f80 Fix g++ 2.9x ambiguity caused by std::rel_ops operators.
[SVN r28493]
2005-04-26 20:31:35 +00:00
Peter Dimov
66ed4fc9e1 Use different names for the functions to make VC6 happy
[SVN r28492]
2005-04-26 20:16:09 +00:00
Markus Schöpflin
23b64e1358 Fixed lookup problem found on Tru64/CXX6.5
[SVN r28486]
2005-04-26 14:30:42 +00:00
Markus Schöpflin
0aa407e77d Added test for lookup problem found on Tru64/CXX6.5
[SVN r28485]
2005-04-26 14:18:10 +00:00
Fredrik Blomqvist
27d1cf539b fixed dead link to Petter Urkedal's 'More' lib.
[SVN r28134]
2005-04-11 16:57:03 +00:00
Peter Dimov
c7710aad38 mem_fn_dm_test added; removed an unconditional MW workaround in mem_fn
[SVN r27736]
2005-03-18 18:16:18 +00:00
Peter Dimov
4a1c4894c7 bind_function_test added.
[SVN r27721]
2005-03-17 12:09:35 +00:00
Peter Dimov
9f0a516068 1.34 -> 1.33, duh
[SVN r27697]
2005-03-16 12:36:42 +00:00
Peter Dimov
6602068638 Section on operators.
[SVN r27680]
2005-03-15 23:44:42 +00:00
Peter Dimov
c25b216898 bind<R>(&X::m, ...) test added
[SVN r27679]
2005-03-15 23:17:29 +00:00
Peter Dimov
ed817c5b15 Relational operators added
[SVN r27669]
2005-03-15 14:15:38 +00:00
Peter Dimov
7b9a97a758 operator! added
[SVN r27632]
2005-03-13 18:27:38 +00:00
Peter Dimov
b1f05e7268 bind_t now implements function_equal instead of operator==
[SVN r27630]
2005-03-13 17:25:42 +00:00
Peter Dimov
28cb8f8206 bind_dm_test.cpp added.
[SVN r27629]
2005-03-13 15:34:55 +00:00
Peter Dimov
ccd0394b86 __cdecl support added.
[SVN r27590]
2005-03-09 20:09:39 +00:00
Peter Dimov
ee5ab38a63 tru64, MIPS Pro ambiguity fix
[SVN r27182]
2005-02-06 19:53:21 +00:00
Peter Dimov
35a2d208d5 Another R const& to R change.
[SVN r26691]
2005-01-13 14:01:22 +00:00
Peter Dimov
424480e55b Updated to reflect that mem_fn's result_type is now R for data members.
[SVN r26688]
2005-01-13 13:49:25 +00:00
Stefan Slapeta
094d43c6e8 Fix for CW 8.4
[SVN r26315]
2004-11-26 14:06:58 +00:00
Aleksey Gurtovoy
f01e59b682 c++boost.gif -> boost.png replacement
[SVN r25573]
2004-10-05 15:45:52 +00:00
Peter Dimov
9ffd0a08c5 Switched data members to return by value to avoid a const ref to short lived temp problem
[SVN r25058]
2004-09-13 17:43:08 +00:00
Douglas Gregor
4e287df40c Converted to Boost Software License, Version 1.0
[SVN r24055]
2004-07-26 00:32:12 +00:00
Douglas Gregor
5c53d7db2a Documentation update from Jon T. Pedant
[SVN r23847]
2004-07-20 17:03:55 +00:00
Douglas Gregor
0904a14c1a T->type
[SVN r23410]
2004-07-09 00:56:42 +00:00
Toon Knapen
4377e763a5 port to vacpp
[SVN r23057]
2004-06-08 13:43:03 +00:00
Peter Dimov
cc984fad42 Added const operator() overloads
[SVN r22934]
2004-05-26 12:50:25 +00:00
Peter Dimov
53c2e449d1 g++ 2.9x fix
[SVN r22709]
2004-04-30 13:04:51 +00:00
Peter Dimov
74fae199f6 Disabled bind<R&> for CW8 as it cannot parse the overloads.
[SVN r22685]
2004-04-22 15:57:12 +00:00
Dave Abrahams
4a41a09d27 Update skipping of pro7 test
[SVN r22672]
2004-04-20 16:32:51 +00:00
Peter Dimov
2244135e86 Enable bind<R&> for data member pointers.
[SVN r22460]
2004-03-09 12:49:00 +00:00
Peter Dimov
807bbfd434 Next round of MSVC 6/7 fixes.
[SVN r22453]
2004-03-07 16:39:15 +00:00
Peter Dimov
6fbbcd0d3c Another VC 7 fix.
[SVN r22429]
2004-03-04 14:05:50 +00:00
Peter Dimov
21f1171900 Attempt to work around a MSVC 7 bug re F& deduction from void (* const) ().
[SVN r22428]
2004-03-03 13:15:05 +00:00
Peter Dimov
f8f4029628 bind_stateful_test.cpp added.
[SVN r22424]
2004-03-02 18:42:12 +00:00
Peter Dimov
dbf6e0cf4b bind_cv_test.cpp added.
[SVN r22418]
2004-03-02 13:02:49 +00:00
Peter Dimov
8f1bb7f13f bind_const_test.cpp added.
[SVN r22416]
2004-03-01 21:05:02 +00:00
Peter Dimov
6601553820 Unfix unversioned VC++ check again, VC 7.1 still needs it.
[SVN r22377]
2004-02-24 19:49:28 +00:00
Peter Dimov
b6a90777c8 Cv-related fix.
[SVN r22338]
2004-02-20 13:56:22 +00:00
Peter Dimov
ea8c0ef25e bind and mem_fn now support operator== and operator!=
[SVN r21978]
2004-01-26 19:13:17 +00:00
Beman Dawes
f91de70d8e type_traits.htm now type_traits.html
[SVN r21232]
2003-12-11 23:35:43 +00:00
Douglas Gregor
4b97a70f64 Redirects to BoostBook-generated documentation
[SVN r21183]
2003-12-08 14:18:22 +00:00
Peter Dimov
7feefb7313 _MSC_VER use clarified.
[SVN r20992]
2003-11-28 15:35:21 +00:00
Vladimir Prus
46ae046f41 Add V2 Jamfile.
[SVN r20208]
2003-09-29 15:37:57 +00:00
Peter Dimov
673d6b0bf0 Fixed VC7 regression
[SVN r20088]
2003-09-17 11:56:22 +00:00
Dave Abrahams
9ca672c10d CWPro8.3 bug workaround
[SVN r19993]
2003-09-10 15:37:59 +00:00
Dave Abrahams
016a3b8d96 Use the import rule
[SVN r19968]
2003-09-08 17:38:49 +00:00
Peter Dimov
6ed01de60f -Wundef fixes.
[SVN r18788]
2003-06-12 17:09:24 +00:00
Peter Dimov
5f95e4d9de Support for noncopyable function objects (boost::signal)
[SVN r18615]
2003-05-30 17:00:14 +00:00
Peter Dimov
90069948ec Const-correctness patch extended to the NO_VOID_RETURNS code path.
[SVN r18332]
2003-04-29 13:28:57 +00:00
Peter Dimov
367728cafe Bound arguments are now no more const than the object itself.
[SVN r18296]
2003-04-23 22:14:40 +00:00
Douglas Gregor
4be201beba Updated to reflect BoostBook changes
[SVN r17941]
2003-03-15 23:12:35 +00:00
Douglas Gregor
04a438f5f4 Lots of cleanups as BoostBook becomes more strict
[SVN r17871]
2003-03-13 00:29:57 +00:00
Douglas Gregor
b06f6a6d89 Move away from attributes, toward elements
[SVN r17869]
2003-03-13 00:08:34 +00:00
Douglas Gregor
81c8af90ec Import of BoostBook documentation for any, array, bind, function, ref, and
signals libraries.


[SVN r17866]
2003-03-12 23:27:25 +00:00
Peter Dimov
c9db3c51ea Fixed some links.
[SVN r17670]
2003-02-27 11:58:50 +00:00
Peter Dimov
8c09072ead Added copyright to Jamfiles.
[SVN r17363]
2003-02-13 15:41:26 +00:00
Peter Dimov
4876b82a73 Moved bind tests to a subinclude.
[SVN r17030]
2003-01-24 16:05:26 +00:00
Peter Dimov
7b7784d470 Metrowerks precompiled header fix (Bertolt Mildner)
[SVN r16731]
2003-01-02 11:55:47 +00:00
Dave Abrahams
eca328b27c Factor out get_pointer, supply an overload for std::auto_ptr.
[SVN r16672]
2002-12-20 18:15:01 +00:00
Peter Dimov
ad46d513d7 Documented new bind(type<R>(), f, ...) syntax.
[SVN r15932]
2002-10-15 12:45:49 +00:00
Peter Dimov
cc3ebc18b8 Fix for Compaq C++ (Ralf W. Grosse-Kunstleve)
[SVN r15929]
2002-10-15 10:57:08 +00:00
Peter Dimov
5a10daef4d bind(type<R>(), f, ...) alternative syntax support.
[SVN r15928]
2002-10-15 10:51:34 +00:00
Peter Dimov
51e4031aaf Fixed g++ 2.95 problem with bind<void>(...) (reported by Alkis Evlogimenos)
[SVN r15923]
2002-10-14 16:35:26 +00:00
Peter Dimov
55dbef0000 Fix for data member support, result_type was R instead of R const &
[SVN r15409]
2002-09-17 12:41:05 +00:00
Peter Dimov
b63a6a5d99 HTML error fixed.
[SVN r15253]
2002-09-10 16:12:51 +00:00
Peter Dimov
52cc55329b Fixed broken links.
[SVN r15123]
2002-08-31 13:04:52 +00:00
Dave Abrahams
5db80e9a33 Added explicit qualification for intel linux C++
[SVN r15025]
2002-08-21 12:27:03 +00:00
Peter Dimov
3cbc321fa5 Fixed the links in the Files section (reported by Albrecht Fritzsche)
[SVN r14955]
2002-08-19 16:51:06 +00:00
Peter Dimov
2f97add842 Switched to <boost/detail/lightweight_test.hpp> for testing.
[SVN r14932]
2002-08-16 16:41:16 +00:00
Peter Dimov
5345f14829 Redirecting index.html files added.
[SVN r14897]
2002-08-15 18:19:42 +00:00
Peter Dimov
0053801ad2 Data member support added.
[SVN r14640]
2002-07-30 13:01:47 +00:00
Peter Dimov
ad043d1fff implementation-defined changed to unspecified.
[SVN r14629]
2002-07-27 16:05:01 +00:00
Peter Dimov
35ee2f3a52 __fastcall support added.
[SVN r14465]
2002-07-15 14:07:03 +00:00
Dave Abrahams
5b1528f3f4 Fix unversioned VC++ checks
[SVN r14436]
2002-07-13 12:26:19 +00:00
Peter Dimov
2277238db7 Support for ref() as a first argument, allowing noncopyable function objects.
[SVN r14115]
2002-06-08 18:06:32 +00:00
Peter Dimov
bdde6cd8b2 extern C FAQ entry, support for data member pointers documented, etc.
[SVN r14081]
2002-06-04 15:15:04 +00:00
Peter Dimov
b1bfd36270 Fixes for Comeau strict mode on Windows
[SVN r13544]
2002-04-22 21:17:42 +00:00
Douglas Gregor
8a2ad8ca78 boost/ref.hpp:
- Added get_pointer method to return a pointer (instead of a reference)

libs/bind/ref.html:
  - Document get_pointer


[SVN r13322]
2002-03-31 00:24:00 +00:00
Peter Dimov
5bae1b9ad1 Data member pointers support added.
[SVN r13232]
2002-03-20 12:52:40 +00:00
Peter Dimov
620c803fc1 Use inline function placeholders only on Borland C++ to avoid compatibility problems.
[SVN r13172]
2002-03-11 15:38:25 +00:00
Peter Dimov
6fb6b475db Placeholders are now inline functions to avoid data in headers (idea by Yitzhak Sapir)
[SVN r13128]
2002-03-08 12:51:31 +00:00
Peter Dimov
1dbea266a1 Documentation fixes, helper headers added.
[SVN r12804]
2002-02-14 14:41:56 +00:00
46 changed files with 5682 additions and 2018 deletions

1599
bind.html

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,6 @@
#if defined(_MSC_VER) && !defined(__ICL)
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
@@ -12,10 +14,9 @@
//
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/bind.hpp>

View File

@@ -1,4 +1,6 @@
#if defined(_MSC_VER) && !defined(__ICL)
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
@@ -10,10 +12,9 @@
//
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/bind.hpp>

242
doc/ref.xml Normal file
View File

@@ -0,0 +1,242 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
<library name="Ref" dirname="ref" id="ref" last-revision="$Date$">
<libraryinfo>
<author>
<firstname>Jaakko</firstname>
<surname>J&auml;rvi</surname>
</author>
<author>
<firstname>Peter</firstname>
<surname>Dimov</surname>
</author>
<author>
<firstname>Douglas</firstname>
<surname>Gregor</surname>
</author>
<author>
<firstname>Dave</firstname>
<surname>Abrahams</surname>
</author>
<copyright>
<year>1999</year>
<year>2000</year>
<holder>Jaakko J&auml;rvi</holder>
</copyright>
<copyright>
<year>2001</year>
<year>2002</year>
<holder>Peter Dimov</holder>
</copyright>
<copyright>
<year>2002</year>
<holder>David Abrahams</holder>
</copyright>
<legalnotice>
<para>Permission to copy, use, modify, sell and distribute this
software is granted provided this copyright notice appears in
all copies. This software is provided "as is" without express
or implied warranty, and with no claim as to its suitability for
any purpose.
</para>
</legalnotice>
<librarypurpose>A utility library for passing references to generic functions</librarypurpose>
<librarycategory name="category:higher-order"/>
</libraryinfo>
<title>Boost.Ref</title>
<section id="ref.intro">
<title>Introduction</title>
<using-namespace name="boost"/>
<para>The Ref library is a small library that is useful for passing
references to function templates (algorithms) that would usually
take copies of their arguments. It defines the class template
<code><classname>boost::reference_wrapper&lt;T&gt;</classname></code>,
the two functions
<code><functionname>boost::ref</functionname></code> and
<code><functionname>boost::cref</functionname></code> that return
instances of <code>boost::reference_wrapper&lt;T&gt;</code>, and the
two traits classes
<code><classname>boost::is_reference_wrapper&lt;T&gt;</classname></code>
and
<code><classname>boost::unwrap_reference&lt;T&gt;</classname></code>.</para>
<para>The purpose of
<code>boost::reference_wrapper&lt;T&gt;</code> is to
contain a reference to an object of type T. It is primarily used to
"feed" references to function templates (algorithms) that take their
parameter by value.</para>
<para>To support this usage,
<code>boost::reference_wrapper&lt;T&gt;</code> provides an implicit
conversion to <code>T&amp;</code>. This usually allows the function
templates to work on references unmodified.</para>
<para><code>boost::reference_wrapper&lt;T&gt;</code> is
both CopyConstructible and Assignable (ordinary references are not
Assignable).</para>
<para>The expression <code>boost::ref(x)</code>
returns a
<code>boost::reference_wrapper&lt;X&gt;(x)</code> where X
is the type of x. Similarly,
<code>boost::cref(x)</code> returns a
<code>boost::reference_wrapper&lt;X const&gt;(x)</code>.</para>
<para>The expression
<code>boost::is_reference_wrapper&lt;T&gt;::value</code>
is true if T is a <code>reference_wrapper</code>, and
false otherwise.</para>
<para>The type-expression
<code>boost::unwrap_reference&lt;T&gt;::type</code> is T::type if T
is a <code>reference_wrapper</code>, T otherwise.</para>
</section>
<library-reference>
<header name="boost/ref.hpp">
<namespace name="boost">
<class name="reference_wrapper">
<template>
<template-type-parameter name="T"/>
</template>
<purpose>
Contains a reference to an object of type
<computeroutput>T</computeroutput>.
</purpose>
<description>
<para><computeroutput><classname>reference_wrapper</classname></computeroutput>
is primarily used to "feed" references to function templates
(algorithms) that take their parameter by value. It provides
an implicit conversion to
<computeroutput>T&amp;</computeroutput>, which usually allows
the function templates to work on references
unmodified.</para>
</description>
<typedef name="type"><type>T</type></typedef>
<constructor specifiers="explicit">
<parameter name="t">
<paramtype>T&amp;</paramtype>
</parameter>
<effects><simpara>Constructs a
<computeroutput><classname>reference_wrapper</classname></computeroutput>
object that stores a reference to
<computeroutput>t</computeroutput>.</simpara></effects>
<throws><simpara>Does not throw.</simpara></throws>
</constructor>
<method-group name="access">
<method name="conversion-operator" cv="const">
<type>T&amp;</type>
<returns><simpara>The stored reference.</simpara></returns>
<throws><simpara>Does not throw.</simpara></throws>
</method>
<method name="get" cv="const">
<type>T&amp;</type>
<returns><simpara>The stored reference.</simpara></returns>
<throws><simpara>Does not throw.</simpara></throws>
</method>
<method name="get_pointer" cv="const">
<type>T*</type>
<returns><simpara>A pointer to the object referenced by the stored reference.</simpara></returns>
<throws><simpara>Does not throw.</simpara></throws>
</method>
</method-group>
<free-function-group name="constructors">
<function name="ref">
<type>reference_wrapper&lt;T&gt;</type>
<parameter name="t">
<paramtype>T&amp;</paramtype>
</parameter>
<returns><simpara><computeroutput><classname>reference_wrapper</classname>&lt;T&gt;(t)</computeroutput></simpara></returns>
<throws><simpara>Does not throw.</simpara></throws>
</function>
<function name="cref">
<type>reference_wrapper&lt;T const&gt;</type>
<parameter name="t">
<paramtype>T const&amp;</paramtype>
</parameter>
<returns><simpara><computeroutput><classname>reference_wrapper</classname>&lt;T const&gt;(t)</computeroutput></simpara></returns>
<throws><simpara>Does not throw.</simpara></throws>
</function>
</free-function-group>
</class>
<class name="is_reference_wrapper">
<template>
<template-type-parameter name="T"/>
</template>
<purpose>Determine if a type <computeroutput>T</computeroutput> is an instantiation of <computeroutput><classname>reference_wrapper</classname></computeroutput>.</purpose>
<description>
<para>The <computeroutput>value</computeroutput> static
constant will be <computeroutput>true</computeroutput> iff the
type <computeroutput>T</computeroutput> is a specialization of
<computeroutput><classname>reference_wrapper</classname></computeroutput>.</para>
</description>
<static-constant name="value">
<type>bool</type>
<default><emphasis>unspecified</emphasis></default>
</static-constant>
</class>
<class name="unwrap_reference">
<template>
<template-type-parameter name="T"/>
</template>
<purpose>Find the type in a <computeroutput><classname>reference_wrapper</classname></computeroutput>.</purpose>
<description>
<para>The typedef <computeroutput>type</computeroutput> is
<computeroutput>T::type</computeroutput> if
<computeroutput>T</computeroutput> is a
<computeroutput><classname>reference_wrapper</classname></computeroutput>,
<computeroutput>T</computeroutput> otherwise.</para>
</description>
<typedef name="type"><type><emphasis>unspecified</emphasis></type></typedef>
</class>
</namespace>
</header>
</library-reference>
<section id="ref.ack">
<title>Acknowledgements</title>
<using-namespace name="boost"/>
<para><functionname>ref</functionname> and <functionname>cref</functionname>
were originally part of the <libraryname>Tuple</libraryname> library
by Jaakko J&auml;rvi. They were "promoted to boost:: status" by
Peter Dimov because they are generally useful. Douglas Gregor and
Dave Abrahams contributed
<classname>is_reference_wrapper</classname> and
<classname>unwrap_reference</classname>.</para>
</section>
</library>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,74 @@
#ifndef BOOST_BIND_APPLY_HPP_INCLUDED
#define BOOST_BIND_APPLY_HPP_INCLUDED
//
// apply.hpp
//
// Copyright (c) 2002, 2003 Peter Dimov and Multi Media Ltd.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
namespace boost
{
template<class R> struct apply
{
typedef R result_type;
template<class F> result_type operator()(F & f) const
{
return f();
}
template<class F, class A1> result_type operator()(F & f, A1 & a1) const
{
return f(a1);
}
template<class F, class A1, class A2> result_type operator()(F & f, A1 & a1, A2 & a2) const
{
return f(a1, a2);
}
template<class F, class A1, class A2, class A3> result_type operator()(F & f, A1 & a1, A2 & a2, A3 & a3) const
{
return f(a1, a2, a3);
}
template<class F, class A1, class A2, class A3, class A4> result_type operator()(F & f, A1 & a1, A2 & a2, A3 & a3, A4 & a4) const
{
return f(a1, a2, a3, a4);
}
template<class F, class A1, class A2, class A3, class A4, class A5> result_type operator()(F & f, A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5) const
{
return f(a1, a2, a3, a4, a5);
}
template<class F, class A1, class A2, class A3, class A4, class A5, class A6> result_type operator()(F & f, A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6) const
{
return f(a1, a2, a3, a4, a5, a6);
}
template<class F, class A1, class A2, class A3, class A4, class A5, class A6, class A7> result_type operator()(F & f, A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7) const
{
return f(a1, a2, a3, a4, a5, a6, a7);
}
template<class F, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8> result_type operator()(F & f, A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7, A8 & a8) const
{
return f(a1, a2, a3, a4, a5, a6, a7, a8);
}
template<class F, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9> result_type operator()(F & f, A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7, A8 & a8, A9 & a9) const
{
return f(a1, a2, a3, a4, a5, a6, a7, a8, a9);
}
};
} // namespace boost
#endif // #ifndef BOOST_BIND_APPLY_HPP_INCLUDED

View File

@@ -1,8 +1,10 @@
#ifndef BOOST_BIND_ARG_HPP_INCLUDED
#define BOOST_BIND_ARG_HPP_INCLUDED
#if _MSC_VER >= 1020
#pragma once
// MS compatible compilers support #pragma once
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
//
@@ -10,10 +12,9 @@
//
// Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/bind/bind.html for documentation.
//
@@ -25,6 +26,11 @@ template<int I> class arg
{
};
template<int I> bool operator==(arg<I> const &, arg<I> const &)
{
return true;
}
} // namespace boost
#endif // #ifndef BOOST_BIND_ARG_HPP_INCLUDED

View File

@@ -5,10 +5,9 @@
//
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/bind/bind.html for documentation.
//

View File

@@ -5,10 +5,9 @@
//
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/bind/bind.html for documentation.
//

View File

@@ -3,12 +3,11 @@
//
// Do not include this header directly.
//
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
// Copyright (c) 2001-2004 Peter Dimov and Multi Media Ltd.
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/bind/bind.html for documentation.
//
@@ -18,131 +17,131 @@
result_type operator()()
{
list0 a;
BOOST_BIND_EVALUATE;
BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
}
result_type operator()() const
{
list0 a;
BOOST_BIND_EVALUATE;
BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
}
template<class A1> result_type operator()(A1 & a1)
{
list1<A1 &> a(a1);
BOOST_BIND_EVALUATE;
BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
}
template<class A1> result_type operator()(A1 & a1) const
{
list1<A1 &> a(a1);
BOOST_BIND_EVALUATE;
BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
}
template<class A1, class A2> result_type operator()(A1 & a1, A2 & a2)
{
list2<A1 &, A2 &> a(a1, a2);
BOOST_BIND_EVALUATE;
BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
}
template<class A1, class A2> result_type operator()(A1 & a1, A2 & a2) const
{
list2<A1 &, A2 &> a(a1, a2);
BOOST_BIND_EVALUATE;
BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
}
template<class A1, class A2, class A3> result_type operator()(A1 & a1, A2 & a2, A3 & a3)
{
list3<A1 &, A2 &, A3 &> a(a1, a2, a3);
BOOST_BIND_EVALUATE;
BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
}
template<class A1, class A2, class A3> result_type operator()(A1 & a1, A2 & a2, A3 & a3) const
{
list3<A1 &, A2 &, A3 &> a(a1, a2, a3);
BOOST_BIND_EVALUATE;
BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
}
template<class A1, class A2, class A3, class A4> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4)
{
list4<A1 &, A2 &, A3 &, A4 &> a(a1, a2, a3, a4);
BOOST_BIND_EVALUATE;
BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
}
template<class A1, class A2, class A3, class A4> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4) const
{
list4<A1 &, A2 &, A3 &, A4 &> a(a1, a2, a3, a4);
BOOST_BIND_EVALUATE;
BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
}
template<class A1, class A2, class A3, class A4, class A5> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5)
{
list5<A1 &, A2 &, A3 &, A4 &, A5 &> a(a1, a2, a3, a4, a5);
BOOST_BIND_EVALUATE;
BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
}
template<class A1, class A2, class A3, class A4, class A5> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5) const
{
list5<A1 &, A2 &, A3 &, A4 &, A5 &> a(a1, a2, a3, a4, a5);
BOOST_BIND_EVALUATE;
BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
}
template<class A1, class A2, class A3, class A4, class A5, class A6> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6)
{
list6<A1 &, A2 &, A3 &, A4 &, A5 &, A6 &> a(a1, a2, a3, a4, a5, a6);
BOOST_BIND_EVALUATE;
BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
}
template<class A1, class A2, class A3, class A4, class A5, class A6> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6) const
{
list6<A1 &, A2 &, A3 &, A4 &, A5 &, A6 &> a(a1, a2, a3, a4, a5, a6);
BOOST_BIND_EVALUATE;
BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
}
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7)
{
list7<A1 &, A2 &, A3 &, A4 &, A5 &, A6 &, A7 &> a(a1, a2, a3, a4, a5, a6, a7);
BOOST_BIND_EVALUATE;
BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
}
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7) const
{
list7<A1 &, A2 &, A3 &, A4 &, A5 &, A6 &, A7 &> a(a1, a2, a3, a4, a5, a6, a7);
BOOST_BIND_EVALUATE;
BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
}
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7, A8 & a8)
{
list8<A1 &, A2 &, A3 &, A4 &, A5 &, A6 &, A7 &, A8 &> a(a1, a2, a3, a4, a5, a6, a7, a8);
BOOST_BIND_EVALUATE;
BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
}
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7, A8 & a8) const
{
list8<A1 &, A2 &, A3 &, A4 &, A5 &, A6 &, A7 &, A8 &> a(a1, a2, a3, a4, a5, a6, a7, a8);
BOOST_BIND_EVALUATE;
BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
}
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7, A8 & a8, A9 & a9)
{
list9<A1 &, A2 &, A3 &, A4 &, A5 &, A6 &, A7 &, A8 &, A9 &> a(a1, a2, a3, a4, a5, a6, a7, a8, a9);
BOOST_BIND_EVALUATE;
BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
}
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7, A8 & a8, A9 & a9) const
{
list9<A1 &, A2 &, A3 &, A4 &, A5 &, A6 &, A7 &, A8 &, A9 &> a(a1, a2, a3, a4, a5, a6, a7, a8, a9);
BOOST_BIND_EVALUATE;
BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
}
template<class A> result_type eval(A & a)
{
BOOST_BIND_EVALUATE;
BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
}
template<class A> result_type eval(A & a) const
{
BOOST_BIND_EVALUATE;
BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
}
template<class V> void accept(V & v) const
@@ -151,6 +150,11 @@
l_.accept(v);
}
bool compare(this_type const & rhs) const
{
return ref_compare(f_, rhs.f_, 0) && l_ == rhs.l_;
}
private:
F f_;

View File

@@ -0,0 +1,187 @@
#ifndef BOOST_BIND_MAKE_ADAPTABLE_HPP_INCLUDED
#define BOOST_BIND_MAKE_ADAPTABLE_HPP_INCLUDED
//
// make_adaptable.hpp
//
// Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
namespace boost
{
namespace _bi
{
template<class R, class F> class af0
{
public:
typedef R result_type;
explicit af0(F f): f_(f)
{
}
result_type operator()()
{
return f_();
}
result_type operator()() const
{
return f_();
}
private:
F f_;
};
template<class R, class A1, class F> class af1
{
public:
typedef R result_type;
typedef A1 argument_type;
typedef A1 arg1_type;
explicit af1(F f): f_(f)
{
}
result_type operator()(A1 a1)
{
return f_(a1);
}
result_type operator()(A1 a1) const
{
return f_(a1);
}
private:
F f_;
};
template<class R, class A1, class A2, class F> class af2
{
public:
typedef R result_type;
typedef A1 first_argument_type;
typedef A2 second_argument_type;
typedef A1 arg1_type;
typedef A2 arg2_type;
explicit af2(F f): f_(f)
{
}
result_type operator()(A1 a1, A2 a2)
{
return f_(a1, a2);
}
result_type operator()(A1 a1, A2 a2) const
{
return f_(a1, a2);
}
private:
F f_;
};
template<class R, class A1, class A2, class A3, class F> class af3
{
public:
typedef R result_type;
typedef A1 arg1_type;
typedef A2 arg2_type;
typedef A3 arg3_type;
explicit af3(F f): f_(f)
{
}
result_type operator()(A1 a1, A2 a2, A3 a3)
{
return f_(a1, a2, a3);
}
result_type operator()(A1 a1, A2 a2, A3 a3) const
{
return f_(a1, a2, a3);
}
private:
F f_;
};
template<class R, class A1, class A2, class A3, class A4, class F> class af4
{
public:
typedef R result_type;
typedef A1 arg1_type;
typedef A2 arg2_type;
typedef A3 arg3_type;
typedef A4 arg4_type;
explicit af4(F f): f_(f)
{
}
result_type operator()(A1 a1, A2 a2, A3 a3, A4 a4)
{
return f_(a1, a2, a3, a4);
}
result_type operator()(A1 a1, A2 a2, A3 a3, A4 a4) const
{
return f_(a1, a2, a3, a4);
}
private:
F f_;
};
} // namespace _bi
template<class R, class F> _bi::af0<R, F> make_adaptable(F f)
{
return _bi::af0<R, F>(f);
}
template<class R, class A1, class F> _bi::af1<R, A1, F> make_adaptable(F f)
{
return _bi::af1<R, A1, F>(f);
}
template<class R, class A1, class A2, class F> _bi::af2<R, A1, A2, F> make_adaptable(F f)
{
return _bi::af2<R, A1, A2, F>(f);
}
template<class R, class A1, class A2, class A3, class F> _bi::af3<R, A1, A2, A3, F> make_adaptable(F f)
{
return _bi::af3<R, A1, A2, A3, F>(f);
}
template<class R, class A1, class A2, class A3, class A4, class F> _bi::af4<R, A1, A2, A3, A4, F> make_adaptable(F f)
{
return _bi::af4<R, A1, A2, A3, A4, F>(f);
}
} // namespace boost
#endif // #ifndef BOOST_BIND_MAKE_ADAPTABLE_HPP_INCLUDED

View File

@@ -5,10 +5,9 @@
//
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/bind/mem_fn.html for documentation.
//

View File

@@ -5,10 +5,9 @@
//
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/bind/mem_fn.html for documentation.
//
@@ -55,6 +54,16 @@ public:
{
BOOST_MEM_FN_RETURN (t.*f_)();
}
bool operator==(BOOST_MEM_FN_NAME(mf0) const & rhs) const
{
return f_ == rhs.f_;
}
bool operator!=(BOOST_MEM_FN_NAME(mf0) const & rhs) const
{
return f_ != rhs.f_;
}
};
// cmf0
@@ -94,6 +103,16 @@ public:
{
BOOST_MEM_FN_RETURN (t.*f_)();
}
bool operator==(BOOST_MEM_FN_NAME(cmf0) const & rhs) const
{
return f_ == rhs.f_;
}
bool operator!=(BOOST_MEM_FN_NAME(cmf0) const & rhs) const
{
return f_ != rhs.f_;
}
};
// mf1
@@ -139,6 +158,16 @@ public:
{
BOOST_MEM_FN_RETURN (t.*f_)(a1);
}
bool operator==(BOOST_MEM_FN_NAME(mf1) const & rhs) const
{
return f_ == rhs.f_;
}
bool operator!=(BOOST_MEM_FN_NAME(mf1) const & rhs) const
{
return f_ != rhs.f_;
}
};
// cmf1
@@ -179,6 +208,16 @@ public:
{
BOOST_MEM_FN_RETURN (t.*f_)(a1);
}
bool operator==(BOOST_MEM_FN_NAME(cmf1) const & rhs) const
{
return f_ == rhs.f_;
}
bool operator!=(BOOST_MEM_FN_NAME(cmf1) const & rhs) const
{
return f_ != rhs.f_;
}
};
// mf2
@@ -222,6 +261,16 @@ public:
{
BOOST_MEM_FN_RETURN (t.*f_)(a1, a2);
}
bool operator==(BOOST_MEM_FN_NAME(mf2) const & rhs) const
{
return f_ == rhs.f_;
}
bool operator!=(BOOST_MEM_FN_NAME(mf2) const & rhs) const
{
return f_ != rhs.f_;
}
};
// cmf2
@@ -260,6 +309,16 @@ public:
{
BOOST_MEM_FN_RETURN (t.*f_)(a1, a2);
}
bool operator==(BOOST_MEM_FN_NAME(cmf2) const & rhs) const
{
return f_ == rhs.f_;
}
bool operator!=(BOOST_MEM_FN_NAME(cmf2) const & rhs) const
{
return f_ != rhs.f_;
}
};
// mf3
@@ -303,6 +362,16 @@ public:
{
BOOST_MEM_FN_RETURN (t.*f_)(a1, a2, a3);
}
bool operator==(BOOST_MEM_FN_NAME(mf3) const & rhs) const
{
return f_ == rhs.f_;
}
bool operator!=(BOOST_MEM_FN_NAME(mf3) const & rhs) const
{
return f_ != rhs.f_;
}
};
// cmf3
@@ -341,6 +410,16 @@ public:
{
BOOST_MEM_FN_RETURN (t.*f_)(a1, a2, a3);
}
bool operator==(BOOST_MEM_FN_NAME(cmf3) const & rhs) const
{
return f_ == rhs.f_;
}
bool operator!=(BOOST_MEM_FN_NAME(cmf3) const & rhs) const
{
return f_ != rhs.f_;
}
};
// mf4
@@ -384,6 +463,16 @@ public:
{
BOOST_MEM_FN_RETURN (t.*f_)(a1, a2, a3, a4);
}
bool operator==(BOOST_MEM_FN_NAME(mf4) const & rhs) const
{
return f_ == rhs.f_;
}
bool operator!=(BOOST_MEM_FN_NAME(mf4) const & rhs) const
{
return f_ != rhs.f_;
}
};
// cmf4
@@ -422,6 +511,16 @@ public:
{
BOOST_MEM_FN_RETURN (t.*f_)(a1, a2, a3, a4);
}
bool operator==(BOOST_MEM_FN_NAME(cmf4) const & rhs) const
{
return f_ == rhs.f_;
}
bool operator!=(BOOST_MEM_FN_NAME(cmf4) const & rhs) const
{
return f_ != rhs.f_;
}
};
// mf5
@@ -465,6 +564,16 @@ public:
{
BOOST_MEM_FN_RETURN (t.*f_)(a1, a2, a3, a4, a5);
}
bool operator==(BOOST_MEM_FN_NAME(mf5) const & rhs) const
{
return f_ == rhs.f_;
}
bool operator!=(BOOST_MEM_FN_NAME(mf5) const & rhs) const
{
return f_ != rhs.f_;
}
};
// cmf5
@@ -503,6 +612,16 @@ public:
{
BOOST_MEM_FN_RETURN (t.*f_)(a1, a2, a3, a4, a5);
}
bool operator==(BOOST_MEM_FN_NAME(cmf5) const & rhs) const
{
return f_ == rhs.f_;
}
bool operator!=(BOOST_MEM_FN_NAME(cmf5) const & rhs) const
{
return f_ != rhs.f_;
}
};
// mf6
@@ -546,6 +665,16 @@ public:
{
BOOST_MEM_FN_RETURN (t.*f_)(a1, a2, a3, a4, a5, a6);
}
bool operator==(BOOST_MEM_FN_NAME(mf6) const & rhs) const
{
return f_ == rhs.f_;
}
bool operator!=(BOOST_MEM_FN_NAME(mf6) const & rhs) const
{
return f_ != rhs.f_;
}
};
// cmf6
@@ -584,6 +713,16 @@ public:
{
BOOST_MEM_FN_RETURN (t.*f_)(a1, a2, a3, a4, a5, a6);
}
bool operator==(BOOST_MEM_FN_NAME(cmf6) const & rhs) const
{
return f_ == rhs.f_;
}
bool operator!=(BOOST_MEM_FN_NAME(cmf6) const & rhs) const
{
return f_ != rhs.f_;
}
};
// mf7
@@ -627,6 +766,16 @@ public:
{
BOOST_MEM_FN_RETURN (t.*f_)(a1, a2, a3, a4, a5, a6, a7);
}
bool operator==(BOOST_MEM_FN_NAME(mf7) const & rhs) const
{
return f_ == rhs.f_;
}
bool operator!=(BOOST_MEM_FN_NAME(mf7) const & rhs) const
{
return f_ != rhs.f_;
}
};
// cmf7
@@ -665,6 +814,16 @@ public:
{
BOOST_MEM_FN_RETURN (t.*f_)(a1, a2, a3, a4, a5, a6, a7);
}
bool operator==(BOOST_MEM_FN_NAME(cmf7) const & rhs) const
{
return f_ == rhs.f_;
}
bool operator!=(BOOST_MEM_FN_NAME(cmf7) const & rhs) const
{
return f_ != rhs.f_;
}
};
// mf8
@@ -708,6 +867,16 @@ public:
{
BOOST_MEM_FN_RETURN (t.*f_)(a1, a2, a3, a4, a5, a6, a7, a8);
}
bool operator==(BOOST_MEM_FN_NAME(mf8) const & rhs) const
{
return f_ == rhs.f_;
}
bool operator!=(BOOST_MEM_FN_NAME(mf8) const & rhs) const
{
return f_ != rhs.f_;
}
};
// cmf8
@@ -751,5 +920,15 @@ public:
{
BOOST_MEM_FN_RETURN (t.*f_)(a1, a2, a3, a4, a5, a6, a7, a8);
}
bool operator==(BOOST_MEM_FN_NAME(cmf8) const & rhs) const
{
return f_ == rhs.f_;
}
bool operator!=(BOOST_MEM_FN_NAME(cmf8) const & rhs) const
{
return f_ != rhs.f_;
}
};

View File

@@ -5,10 +5,9 @@
//
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/bind/mem_fn.html for documentation.
//

View File

@@ -1,8 +1,10 @@
#ifndef BOOST_BIND_PLACEHOLDERS_HPP_INCLUDED
#define BOOST_BIND_PLACEHOLDERS_HPP_INCLUDED
#if _MSC_VER >= 1020
#pragma once
// MS compatible compilers support #pragma once
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
//
@@ -10,10 +12,9 @@
//
// Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/bind/bind.html for documentation.
//
@@ -21,29 +22,47 @@
#include <boost/bind/arg.hpp>
#include <boost/config.hpp>
// With MSVC precompiled headers, unnamed namespaces are not unique
#ifdef BOOST_MSVC
# define BOOST_BIND_STATIC static
#else
# define BOOST_BIND_STATIC
#endif
namespace
{
BOOST_BIND_STATIC boost::arg<1> _1;
BOOST_BIND_STATIC boost::arg<2> _2;
BOOST_BIND_STATIC boost::arg<3> _3;
BOOST_BIND_STATIC boost::arg<4> _4;
BOOST_BIND_STATIC boost::arg<5> _5;
BOOST_BIND_STATIC boost::arg<6> _6;
BOOST_BIND_STATIC boost::arg<7> _7;
BOOST_BIND_STATIC boost::arg<8> _8;
BOOST_BIND_STATIC boost::arg<9> _9;
#if defined(__BORLANDC__)
static inline boost::arg<1> _1() { return boost::arg<1>(); }
static inline boost::arg<2> _2() { return boost::arg<2>(); }
static inline boost::arg<3> _3() { return boost::arg<3>(); }
static inline boost::arg<4> _4() { return boost::arg<4>(); }
static inline boost::arg<5> _5() { return boost::arg<5>(); }
static inline boost::arg<6> _6() { return boost::arg<6>(); }
static inline boost::arg<7> _7() { return boost::arg<7>(); }
static inline boost::arg<8> _8() { return boost::arg<8>(); }
static inline boost::arg<9> _9() { return boost::arg<9>(); }
#elif defined(BOOST_MSVC) || (defined(__DECCXX_VER) && __DECCXX_VER <= 60590031) || defined(__MWERKS__)
static boost::arg<1> _1;
static boost::arg<2> _2;
static boost::arg<3> _3;
static boost::arg<4> _4;
static boost::arg<5> _5;
static boost::arg<6> _6;
static boost::arg<7> _7;
static boost::arg<8> _8;
static boost::arg<9> _9;
#else
boost::arg<1> _1;
boost::arg<2> _2;
boost::arg<3> _3;
boost::arg<4> _4;
boost::arg<5> _5;
boost::arg<6> _6;
boost::arg<7> _7;
boost::arg<8> _8;
boost::arg<9> _9;
#endif
} // unnamed namespace
#undef BOOST_BIND_STATIC
#endif // #ifndef BOOST_BIND_PLACEHOLDERS_HPP_INCLUDED

View File

@@ -0,0 +1,144 @@
#ifndef BOOST_BIND_PROTECT_HPP_INCLUDED
#define BOOST_BIND_PROTECT_HPP_INCLUDED
//
// protect.hpp
//
// Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
namespace boost
{
namespace _bi
{
template<class F> class protected_bind_t
{
public:
typedef typename F::result_type result_type;
explicit protected_bind_t(F f): f_(f)
{
}
result_type operator()()
{
return f_();
}
result_type operator()() const
{
return f_();
}
template<class A1> result_type operator()(A1 & a1)
{
return f_(a1);
}
template<class A1> result_type operator()(A1 & a1) const
{
return f_(a1);
}
template<class A1, class A2> result_type operator()(A1 & a1, A2 & a2)
{
return f_(a1, a2);
}
template<class A1, class A2> result_type operator()(A1 & a1, A2 & a2) const
{
return f_(a1, a2);
}
template<class A1, class A2, class A3> result_type operator()(A1 & a1, A2 & a2, A3 & a3)
{
return f_(a1, a2, a3);
}
template<class A1, class A2, class A3> result_type operator()(A1 & a1, A2 & a2, A3 & a3) const
{
return f_(a1, a2, a3);
}
template<class A1, class A2, class A3, class A4> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4)
{
return f_(a1, a2, a3, a4);
}
template<class A1, class A2, class A3, class A4> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4) const
{
return f_(a1, a2, a3, a4);
}
template<class A1, class A2, class A3, class A4, class A5> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5)
{
return f_(a1, a2, a3, a4, a5);
}
template<class A1, class A2, class A3, class A4, class A5> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5) const
{
return f_(a1, a2, a3, a4, a5);
}
template<class A1, class A2, class A3, class A4, class A5, class A6> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6)
{
return f_(a1, a2, a3, a4, a5, a6);
}
template<class A1, class A2, class A3, class A4, class A5, class A6> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6) const
{
return f_(a1, a2, a3, a4, a5, a6);
}
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7)
{
return f_(a1, a2, a3, a4, a5, a6, a7);
}
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7) const
{
return f_(a1, a2, a3, a4, a5, a6, a7);
}
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7, A8 & a8)
{
return f_(a1, a2, a3, a4, a5, a6, a7, a8);
}
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7, A8 & a8) const
{
return f_(a1, a2, a3, a4, a5, a6, a7, a8);
}
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7, A8 & a8, A9 & a9)
{
return f_(a1, a2, a3, a4, a5, a6, a7, a8, a9);
}
template<class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9> result_type operator()(A1 & a1, A2 & a2, A3 & a3, A4 & a4, A5 & a5, A6 & a6, A7 & a7, A8 & a8, A9 & a9) const
{
return f_(a1, a2, a3, a4, a5, a6, a7, a8, a9);
}
private:
F f_;
};
} // namespace _bi
template<class F> _bi::protected_bind_t<F> protect(F f)
{
return _bi::protected_bind_t<F>(f);
}
} // namespace boost
#endif // #ifndef BOOST_BIND_PROTECT_HPP_INCLUDED

View File

@@ -1,38 +1,33 @@
#ifndef BOOST_MEM_FN_HPP_INCLUDED
#define BOOST_MEM_FN_HPP_INCLUDED
#if _MSC_VER+0 >= 1020
#pragma once
// MS compatible compilers support #pragma once
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
//
// mem_fn.hpp - a generalization of std::mem_fun[_ref]
//
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
// Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
// Copyright (c) 2001 David Abrahams
// Copyright (c) 2003-2005 Peter Dimov
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/bind/mem_fn.html for documentation.
//
#include <boost/config.hpp>
#include <boost/get_pointer.hpp>
#include <boost/detail/workaround.hpp>
namespace boost
{
// get_pointer(p) extracts a ->* capable pointer from p
template<class T> T * get_pointer(T * p)
{
return p;
}
// get_pointer(shared_ptr<T> const & p) has been moved to shared_ptr.hpp
#if defined(BOOST_NO_VOID_RETURNS)
#define BOOST_MEM_FN_CLASS_F , class F
@@ -54,6 +49,18 @@ template<class V> struct mf
#undef BOOST_MEM_FN_CC
#undef BOOST_MEM_FN_NAME
#ifdef BOOST_MEM_FN_ENABLE_CDECL
#define BOOST_MEM_FN_NAME(X) inner_##X##_cdecl
#define BOOST_MEM_FN_CC __cdecl
#include <boost/bind/mem_fn_template.hpp>
#undef BOOST_MEM_FN_CC
#undef BOOST_MEM_FN_NAME
#endif
#ifdef BOOST_MEM_FN_ENABLE_STDCALL
#define BOOST_MEM_FN_NAME(X) inner_##X##_stdcall
@@ -66,6 +73,18 @@ template<class V> struct mf
#endif
#ifdef BOOST_MEM_FN_ENABLE_FASTCALL
#define BOOST_MEM_FN_NAME(X) inner_##X##_fastcall
#define BOOST_MEM_FN_CC __fastcall
#include <boost/bind/mem_fn_template.hpp>
#undef BOOST_MEM_FN_CC
#undef BOOST_MEM_FN_NAME
#endif
#undef BOOST_MEM_FN_RETURN
}; // struct mf<V>
@@ -83,6 +102,18 @@ template<> struct mf<void>
#undef BOOST_MEM_FN_CC
#undef BOOST_MEM_FN_NAME
#ifdef BOOST_MEM_FN_ENABLE_CDECL
#define BOOST_MEM_FN_NAME(X) inner_##X##_cdecl
#define BOOST_MEM_FN_CC __cdecl
#include <boost/bind/mem_fn_template.hpp>
#undef BOOST_MEM_FN_CC
#undef BOOST_MEM_FN_NAME
#endif
#ifdef BOOST_MEM_FN_ENABLE_STDCALL
#define BOOST_MEM_FN_NAME(X) inner_##X##_stdcall
@@ -95,6 +126,18 @@ template<> struct mf<void>
#endif
#ifdef BOOST_MEM_FN_ENABLE_FASTCALL
#define BOOST_MEM_FN_NAME(X) inner_##X##_fastcall
#define BOOST_MEM_FN_CC __fastcall
#include <boost/bind/mem_fn_template.hpp>
#undef BOOST_MEM_FN_CC
#undef BOOST_MEM_FN_NAME
#endif
#undef BOOST_MEM_FN_RETURN
}; // struct mf<void>
@@ -112,6 +155,20 @@ template<> struct mf<void>
#undef BOOST_MEM_FN_NAME2
#undef BOOST_MEM_FN_CC
#ifdef BOOST_MEM_FN_ENABLE_CDECL
#define BOOST_MEM_FN_NAME(X) X##_cdecl
#define BOOST_MEM_FN_NAME2(X) inner_##X##_cdecl
#define BOOST_MEM_FN_CC __cdecl
#include <boost/bind/mem_fn_vw.hpp>
#undef BOOST_MEM_FN_NAME
#undef BOOST_MEM_FN_NAME2
#undef BOOST_MEM_FN_CC
#endif
#ifdef BOOST_MEM_FN_ENABLE_STDCALL
#define BOOST_MEM_FN_NAME(X) X##_stdcall
@@ -126,6 +183,20 @@ template<> struct mf<void>
#endif
#ifdef BOOST_MEM_FN_ENABLE_FASTCALL
#define BOOST_MEM_FN_NAME(X) X##_fastcall
#define BOOST_MEM_FN_NAME2(X) inner_##X##_fastcall
#define BOOST_MEM_FN_CC __fastcall
#include <boost/bind/mem_fn_vw.hpp>
#undef BOOST_MEM_FN_NAME
#undef BOOST_MEM_FN_NAME2
#undef BOOST_MEM_FN_CC
#endif
} // namespace _mfi
#else // #ifdef BOOST_NO_VOID_RETURNS
@@ -146,6 +217,18 @@ namespace _mfi
#undef BOOST_MEM_FN_CC
#undef BOOST_MEM_FN_NAME
#ifdef BOOST_MEM_FN_ENABLE_CDECL
#define BOOST_MEM_FN_NAME(X) X##_cdecl
#define BOOST_MEM_FN_CC __cdecl
#include <boost/bind/mem_fn_template.hpp>
#undef BOOST_MEM_FN_CC
#undef BOOST_MEM_FN_NAME
#endif
#ifdef BOOST_MEM_FN_ENABLE_STDCALL
#define BOOST_MEM_FN_NAME(X) X##_stdcall
@@ -158,6 +241,18 @@ namespace _mfi
#endif
#ifdef BOOST_MEM_FN_ENABLE_FASTCALL
#define BOOST_MEM_FN_NAME(X) X##_fastcall
#define BOOST_MEM_FN_CC __fastcall
#include <boost/bind/mem_fn_template.hpp>
#undef BOOST_MEM_FN_CC
#undef BOOST_MEM_FN_NAME
#endif
#undef BOOST_MEM_FN_RETURN
} // namespace _mfi
@@ -175,6 +270,18 @@ namespace _mfi
#undef BOOST_MEM_FN_NAME
#undef BOOST_MEM_FN_CC
#ifdef BOOST_MEM_FN_ENABLE_CDECL
#define BOOST_MEM_FN_NAME(X) X##_cdecl
#define BOOST_MEM_FN_CC __cdecl
#include <boost/bind/mem_fn_cc.hpp>
#undef BOOST_MEM_FN_NAME
#undef BOOST_MEM_FN_CC
#endif
#ifdef BOOST_MEM_FN_ENABLE_STDCALL
#define BOOST_MEM_FN_NAME(X) X##_stdcall
@@ -187,6 +294,101 @@ namespace _mfi
#endif
#ifdef BOOST_MEM_FN_ENABLE_FASTCALL
#define BOOST_MEM_FN_NAME(X) X##_fastcall
#define BOOST_MEM_FN_CC __fastcall
#include <boost/bind/mem_fn_cc.hpp>
#undef BOOST_MEM_FN_NAME
#undef BOOST_MEM_FN_CC
#endif
// data member support
namespace _mfi
{
template<class R, class T> class dm
{
public:
typedef R const & result_type;
typedef T const * argument_type;
private:
typedef R (T::*F);
F f_;
template<class U> R const & call(U & u, T const *) const
{
return (u.*f_);
}
template<class U> R & call(U & u, T *) const
{
return (u.*f_);
}
template<class U> R const & call(U & u, void const *) const
{
return (get_pointer(u)->*f_);
}
public:
explicit dm(F f): f_(f) {}
R & operator()(T * p) const
{
return (p->*f_);
}
R const & operator()(T const * p) const
{
return (p->*f_);
}
template<class U> R const & operator()(U & u) const
{
return call(u, &u);
}
#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) && !BOOST_WORKAROUND(__MWERKS__, < 0x3200)
R & operator()(T & t) const
{
return (t.*f_);
}
#endif
R const & operator()(T const & t) const
{
return (t.*f_);
}
bool operator==(dm const & rhs) const
{
return f_ == rhs.f_;
}
bool operator!=(dm const & rhs) const
{
return f_ != rhs.f_;
}
};
} // namespace _mfi
template<class R, class T> _mfi::dm<R, T> mem_fn(R T::*f)
{
return _mfi::dm<R, T>(f);
}
} // namespace boost
#endif // #ifndef BOOST_MEM_FN_HPP_INCLUDED

10
index.html Normal file
View File

@@ -0,0 +1,10 @@
<html>
<head>
<meta http-equiv="refresh" content="0; URL=bind.html">
</head>
<body>
Automatic redirection failed, please go to
<a href="bind.html">bind.html</a> or
<a href="mem_fn.html">mem_fn.html</a>.
</body>
</html>

View File

@@ -1,116 +1,98 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Boost: mem_fn.hpp documentation</title>
</head>
<body bgcolor="White" style="margin-left: 5%; margin-right: 5%;">
<table border="0" width="100%">
<tr>
<td width="277">
<img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" width="277" height="86">
</td>
<td align="center">
<h1>mem_fn.hpp</h1>
</td>
</tr>
<tr>
<td colspan="2" height="64">&nbsp;</td>
</tr>
</table>
<h2>Contents</h2>
<h3 style="margin-left: 20pt;"><a href="#Purpose">Purpose</a></h3>
<h3 style="margin-left: 20pt;"><a href="#FAQ">Frequently Asked Questions</a></h3>
<h4 style="margin-left: 40pt;"><a href="#Q1">Can <b>mem_fn</b> be used instead of the standard
<b>std::mem_fun[_ref]</b> adaptors?</a></h4>
<h4 style="margin-left: 40pt;"><a href="#Q2">Should I replace every occurence of <b>std::mem_fun[_ref]</b>
with <b>mem_fn</b> in my existing code?</a></h4>
<h4 style="margin-left: 40pt;"><a href="#Q3">Does <b>mem_fn</b> work with COM methods?</a></h4>
<h4 style="margin-left: 40pt;"><a href="#Q4">Why isn't BOOST_MEM_FN_ENABLE_STDCALL defined automatically?</a></h4>
<h3 style="margin-left: 20pt;"><a href="#Interface">Interface</a></h3>
<h4 style="margin-left: 40pt;"><a href="#Synopsis">Synopsis</a></h4>
<h4 style="margin-left: 40pt;"><a href="#CommonRequirements">Common requirements</a></h4>
<h4 style="margin-left: 40pt;"><a href="#get_pointer">get_pointer</a></h4>
<h4 style="margin-left: 40pt;"><a href="#mem_fn">mem_fn</a></h4>
<h3 style="margin-left: 20pt;"><a href="#Implementation">Implementation</a></h3>
<h4 style="margin-left: 40pt;"><a href="#Files">Files</a></h4>
<h4 style="margin-left: 40pt;"><a href="#Dependencies">Dependencies</a></h4>
<h4 style="margin-left: 40pt;"><a href="#NumberOfArguments">Number of Arguments</a></h4>
<h4 style="margin-left: 40pt;"><a href="#stdcall">&quot;__stdcall&quot; Support</a></h4>
<h3 style="margin-left: 20pt;"><a href="#Acknowledgements">Acknowledgements</a></h3>
<h2><a name="Purpose">Purpose</a></h2>
<p>
<b>boost::mem_fn</b> is a generalization of the standard functions
<b>std::mem_fun</b> and <b>std::mem_fun_ref</b>. It supports member
function pointers with more than one argument, and the returned function
object can take a pointer, a reference, or a smart pointer to an object
instance as its first argument.
</p>
<p>
The purpose of <b>mem_fn</b> is twofold. First, it allows users to invoke a
member function on a container with the familiar
</p>
<pre>
<head>
<title>Boost: mem_fn.hpp documentation</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="white" style="MARGIN-LEFT: 5%; MARGIN-RIGHT: 5%">
<table border="0" width="100%">
<tr>
<td width="277">
<img src="../../boost.png" alt="boost.png (6897 bytes)" width="277" height="86">
</td>
<td align="center">
<h1>mem_fn.hpp</h1>
</td>
</tr>
<tr>
<td colspan="2" height="64">&nbsp;</td>
</tr>
</table>
<h2>Contents</h2>
<h3 style="MARGIN-LEFT: 20pt"><a href="#Purpose">Purpose</a></h3>
<h3 style="MARGIN-LEFT: 20pt"><a href="#FAQ">Frequently Asked Questions</a></h3>
<h4 style="MARGIN-LEFT: 40pt"><a href="#Q1">Can <b>mem_fn</b> be used instead of the
standard <b>std::mem_fun[_ref]</b> adaptors?</a></h4>
<h4 style="MARGIN-LEFT: 40pt"><a href="#Q2">Should I replace every occurence of <b>std::mem_fun[_ref]</b>
with <b>mem_fn</b> in my existing code?</a></h4>
<h4 style="MARGIN-LEFT: 40pt"><a href="#Q3">Does <b>mem_fn</b> work with COM methods?</a></h4>
<h4 style="MARGIN-LEFT: 40pt"><a href="#Q4">Why isn't BOOST_MEM_FN_ENABLE_STDCALL
defined automatically?</a></h4>
<h3 style="MARGIN-LEFT: 20pt"><a href="#Interface">Interface</a></h3>
<h4 style="MARGIN-LEFT: 40pt"><a href="#Synopsis">Synopsis</a></h4>
<h4 style="MARGIN-LEFT: 40pt"><a href="#CommonRequirements">Common requirements</a></h4>
<h4 style="MARGIN-LEFT: 40pt"><a href="#get_pointer">get_pointer</a></h4>
<h4 style="MARGIN-LEFT: 40pt"><a href="#mem_fn">mem_fn</a></h4>
<h3 style="MARGIN-LEFT: 20pt"><a href="#Implementation">Implementation</a></h3>
<h4 style="MARGIN-LEFT: 40pt"><a href="#Files">Files</a></h4>
<h4 style="MARGIN-LEFT: 40pt"><a href="#Dependencies">Dependencies</a></h4>
<h4 style="MARGIN-LEFT: 40pt"><a href="#NumberOfArguments">Number of Arguments</a></h4>
<h4 style="MARGIN-LEFT: 40pt"><a href="#stdcall">"__stdcall", "__cdecl" and
"__fastcall" Support</a></h4>
<h3 style="MARGIN-LEFT: 20pt"><a href="#Acknowledgements">Acknowledgements</a></h3>
<h2><a name="Purpose">Purpose</a></h2>
<p>
<b>boost::mem_fn</b> is a generalization of the standard functions <b>std::mem_fun</b>
and <b>std::mem_fun_ref</b>. It supports member function pointers with more
than one argument, and the returned function object can take a pointer, a
reference, or a smart pointer to an object instance as its first argument. <STRONG>mem_fn</STRONG>
also supports pointers to data members by treating them as functions taking no
arguments and returning a (const) reference to the member.
</p>
<p>
The purpose of <b>mem_fn</b> is twofold. First, it allows users to invoke a
member function on a container with the familiar
</p>
<pre>
std::for_each(v.begin(), v.end(), boost::mem_fn(&amp;Shape::draw));
</pre>
<p>
syntax, even when the container stores smart pointers.
</p>
<p>
Second, it can be used as a building block by library developers that want
to treat a pointer to member function as a function object. A library might
define an enhanced <b>for_each</b> algorithm with an overload of the form:
</p>
<pre>
<p>
syntax, even when the container stores smart pointers.
</p>
<p>
Second, it can be used as a building block by library developers that want to
treat a pointer to member function as a function object. A library might define
an enhanced <b>for_each</b> algorithm with an overload of the form:
</p>
<pre>
template&lt;class It, class R, class T&gt; void for_each(It first, It last, R (T::*pmf) ())
{
std::for_each(first, last, boost::mem_fn(pmf));
}
</pre>
<p>
that will allow the convenient syntax:
</p>
<pre>
<p>
that will allow the convenient syntax:
</p>
<pre>
for_each(v.begin(), v.end(), &amp;Shape::draw);
</pre>
<p>
When documenting the feature, the library author will simply state:
</p>
<h4 style="margin-left: 20pt;">template&lt;class It, class R, class T&gt; void for_each(It first, It last, R (T::*pmf) ());</h4>
<p style="margin-left: 20pt;">
<b>Effects:</b> equivalent to std::for_each(first, last, boost::mem_fn(pmf));
</p>
<p>
where <b>boost::mem_fn</b> can be a link to this page. See
<a href="bind.html">the documentation of <b>bind</b></a> for an example.
</p>
<p>
<b>mem_fn</b> takes one argument, a pointer to a member function, and
returns a function object suitable for use with standard or user-defined
algorithms:
</p>
<pre>
<p>
When documenting the feature, the library author will simply state:
</p>
<h4 style="MARGIN-LEFT: 20pt">template&lt;class It, class R, class T&gt; void
for_each(It first, It last, R (T::*pmf) ());</h4>
<p style="MARGIN-LEFT: 20pt">
<b>Effects:</b> equivalent to std::for_each(first, last, boost::mem_fn(pmf));
</p>
<p>
where <b>boost::mem_fn</b> can be a link to this page. See <a href="bind.html">the
documentation of <b>bind</b></a> for an example.
</p>
<p>
<b>mem_fn</b> takes one argument, a pointer to a member, and returns a function
object suitable for use with standard or user-defined algorithms:
</p>
<pre>
struct X
{
void f();
@@ -131,297 +113,298 @@ void k(std::vector&lt;boost::shared_ptr&lt;X&gt; &gt; const &amp; v)
std::for_each(v.begin(), v.end(), boost::mem_fn(&amp;X::f));
};
</pre>
<p>
The returned function object takes the same arguments as the input member
function plus a "flexible" first argument that represents the object instance.
</p>
<p>
When the function object is invoked with a first argument <b>x</b> that is
neither a pointer nor a reference to the appropriate class (<b>X</b> in the
example above), it uses <tt>get_pointer(x)</tt> to obtain a pointer from
<b>x</b>. Library authors can "register" their smart pointer classes by
supplying an appropriate <b>get_pointer</b> overload, allowing <b>mem_fn</b>
to recognize and support them.
</p>
<p>
A <b>get_pointer</b> overload for <b>boost::shared_ptr</b> is supplied.
</p>
<p>
[Note: <b>get_pointer</b> is not restricted to return a pointer. Any object
that can be used in a member function call expression <tt>(x->*pmf)(...)</tt>
will work.]
</p>
<p>
[Note: the library uses an unqualified call to <b>get_pointer</b>. Therefore,
it will find, through argument-dependent lookup, <b>get_pointer</b> overloads
that are defined in the same namespace as the corresponding smart pointer
class, in addition to any <b>boost::get_pointer</b> overloads.]
</p>
<p>
All function objects returned by <b>mem_fn</b> expose a <b>result_type</b>
typedef that represents the return type of the member function.
</p>
<h2><a name="FAQ">Frequently Asked Questions</a></h2>
<h3><a name="Q1">Can <b>mem_fn</b> be used instead of the standard
<b>std::mem_fun[_ref]</b> adaptors?</a></h3>
<p>
Yes. For simple uses, <b>mem_fn</b> provides additional functionality that
the standard adaptors do not. Complicated expressions that use <b>std::bind1st</b>,
<b>std::bind2nd</b> or <a href="../compose/index.htm"><b>Boost.Compose</b></a>
along with the standard adaptors can be rewritten using
<a href="bind.html"><b>boost::bind</b></a> that automatically takes advantage of
<b>mem_fn</b>.
</p>
<h3><a name="Q2">Should I replace every occurence of <b>std::mem_fun[_ref]</b>
with <b>mem_fn</b> in my existing code?</a></h3>
<p>
No, unless you have good reasons to do so. <b>mem_fn</b> is not 100% compatible
with the standard adaptors, although it comes pretty close. In particular,
<b>mem_fn</b> does not return objects of type
<b>std::[const_]mem_fun[1][_ref]_t</b>, as the standard adaptors do, and it is
not possible to fully describe the type of the first argument using the standard
<b>argument_type</b> and <b>first_argument_type</b> nested typedefs. Libraries
that need adaptable function objects in order to function might not like
<b>mem_fn</b>.
</p>
<h3><a name="Q3">Does <b>mem_fn</b> work with COM methods?</a></h3>
<p>
Yes, if you <a href="#stdcall">#define BOOST_MEM_FN_ENABLE_STDCALL</a>.
</p>
<h3><a name="Q4">Why isn't BOOST_MEM_FN_ENABLE_STDCALL defined automatically?</a></h3>
<p>
Non-portable extensions, in general, should default to off to prevent vendor
lock-in. Had BOOST_MEM_FN_ENABLE_STDCALL been defined automatically, you could
have accidentally taken advantage of it without realizing that your code is,
perhaps, no longer portable.
</p>
<h2><a name="Interface">Interface</a></h2>
<h3><a name="Synopsis">Synopsis</a></h3>
<pre>
<p>
The returned function object takes the same arguments as the input member
function plus a "flexible" first argument that represents the object instance.
</p>
<p>
When the function object is invoked with a first argument <b>x</b> that is
neither a pointer nor a reference to the appropriate class (<b>X</b> in the
example above), it uses <tt>get_pointer(x)</tt> to obtain a pointer from <b>x</b>.
Library authors can "register" their smart pointer classes by supplying an
appropriate <b>get_pointer</b> overload, allowing <b>mem_fn</b> to recognize
and support them.
</p>
<p>
[Note: <b>get_pointer</b> is not restricted to return a pointer. Any object
that can be used in a member function call expression <tt>(x-&gt;*pmf)(...)</tt>
will work.]
</p>
<p>
[Note: the library uses an unqualified call to <b>get_pointer</b>. Therefore,
it will find, through argument-dependent lookup, <b>get_pointer</b> overloads
that are defined in the same namespace as the corresponding smart pointer
class, in addition to any <b>boost::get_pointer</b> overloads.]
</p>
<p>
All function objects returned by <b>mem_fn</b> expose a <b>result_type</b> typedef
that represents the return type of the member function. For data members, <STRONG>result_type</STRONG>
is defined as the type of the member.
</p>
<h2><a name="FAQ">Frequently Asked Questions</a></h2>
<h3><a name="Q1">Can <b>mem_fn</b> be used instead of the standard <b>std::mem_fun[_ref]</b>
adaptors?</a></h3>
<p>
Yes. For simple uses, <b>mem_fn</b> provides additional functionality that the
standard adaptors do not. Complicated expressions that use <b>std::bind1st</b>, <b>std::bind2nd</b>
or <a href="../compose/index.htm"><b>Boost.Compose</b></a> along with the
standard adaptors can be rewritten using <a href="bind.html"><b>boost::bind</b></a>
that automatically takes advantage of <b>mem_fn</b>.
</p>
<h3><a name="Q2">Should I replace every occurence of <b>std::mem_fun[_ref]</b> with <b>mem_fn</b>
in my existing code?</a></h3>
<p>
No, unless you have good reasons to do so. <b>mem_fn</b> is not 100% compatible
with the standard adaptors, although it comes pretty close. In particular, <b>mem_fn</b>
does not return objects of type <b>std::[const_]mem_fun[1][_ref]_t</b>, as the
standard adaptors do, and it is not possible to fully describe the type of the
first argument using the standard <b>argument_type</b> and <b>first_argument_type</b>
nested typedefs. Libraries that need adaptable function objects in order to
function might not like <b>mem_fn</b>.
</p>
<h3><a name="Q3">Does <b>mem_fn</b> work with COM methods?</a></h3>
<p>
Yes, if you <a href="#stdcall">#define BOOST_MEM_FN_ENABLE_STDCALL</a>.
</p>
<h3><a name="Q4">Why isn't BOOST_MEM_FN_ENABLE_STDCALL defined automatically?</a></h3>
<p>
Non-portable extensions, in general, should default to
off to prevent vendor lock-in. Had BOOST_MEM_FN_ENABLE_STDCALL been defined
automatically, you could have accidentally taken advantage of
it without realizing that your code is, perhaps, no longer portable.
In addition, it is possible for the default
calling convention to be __stdcall, in which case enabling __stdcall support will
result in duplicate definitions.
</p>
<h2><a name="Interface">Interface</a></h2>
<h3><a name="Synopsis">Synopsis</a></h3>
<pre>
namespace boost
{
template&lt;class T&gt; T * <a href="#get_pointer_1">get_pointer</a>(T * p);
template&lt;class T&gt; T * <a href="#get_pointer_2">get_pointer</a>(shared_ptr&lt;T&gt; const &amp; p);
template&lt;class R, class T&gt; <i>unspecified-1</i> <a href="#mem_fn_1">mem_fn</a>(R (T::*pmf) ());
template&lt;class R, class T&gt; <i>implementation-defined-1</i> <a href="#mem_fn_1">mem_fn</a>(R (T::*pmf) ());
template&lt;class R, class T&gt; <i>unspecified-2</i> <a href="#mem_fn_2">mem_fn</a>(R (T::*pmf) () const);
template&lt;class R, class T&gt; <i>implementation-defined-2</i> <a href="#mem_fn_2">mem_fn</a>(R (T::*pmf) () const);
template&lt;class R, class T&gt; <i>unspecified-2-1</i> <a href="#mem_fn_2_1">mem_fn</a>(R T::*pm);
template&lt;class R, class T, class A1&gt; <i>implementation-defined-3</i> <a href="#mem_fn_3">mem_fn</a>(R (T::*pmf) (A1));
template&lt;class R, class T, class A1&gt; <i>unspecified-3</i> <a href="#mem_fn_3">mem_fn</a>(R (T::*pmf) (A1));
template&lt;class R, class T, class A1&gt; <i>implementation-defined-4</i> <a href="#mem_fn_4">mem_fn</a>(R (T::*pmf) (A1) const);
template&lt;class R, class T, class A1&gt; <i>unspecified-4</i> <a href="#mem_fn_4">mem_fn</a>(R (T::*pmf) (A1) const);
template&lt;class R, class T, class A1, class A2&gt; <i>implementation-defined-5</i> <a href="#mem_fn_5">mem_fn</a>(R (T::*pmf) (A1, A2));
template&lt;class R, class T, class A1, class A2&gt; <i>unspecified-5</i> <a href="#mem_fn_5">mem_fn</a>(R (T::*pmf) (A1, A2));
template&lt;class R, class T, class A1, class A2&gt; <i>implementation-defined-6</i> <a href="#mem_fn_6">mem_fn</a>(R (T::*pmf) (A1, A2) const);
template&lt;class R, class T, class A1, class A2&gt; <i>unspecified-6</i> <a href="#mem_fn_6">mem_fn</a>(R (T::*pmf) (A1, A2) const);
// implementation defined number of additional overloads for more arguments
}
</pre>
<h3><a name="CommonRequirements">Common requirements</a></h3>
<p>
All <tt><i>implementation-defined-N</i></tt> types mentioned in the Synopsis are
<b>CopyConstructible</b> and <b>Assignable</b>.
Their copy constructors and assignment operators do not throw exceptions.
<tt><i>implementation-defined-N</i>::result_type</tt> is defined as
the return type of the member function pointer passed as an argument to <b>mem_fn</b>
(<b>R</b> in the Synopsis.)
</p>
<h3><a name="get_pointer">get_pointer</a></h3>
<h4><a name="get_pointer_1">template&lt;class T&gt; T * get_pointer(T * p)</a></h4>
<p>
<b>Returns:</b> <tt>p</tt>.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
<h4><a name="get_pointer_2">template&lt;class T&gt; T * get_pointer(shared_ptr&lt;T&gt; const &amp; p)</a></h4>
<p>
<b>Returns:</b> <tt>p.get()</tt>.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
<h3><a name="mem_fn">mem_fn</a></h3>
<h4><a name="mem_fn_1">template&lt;class R, class T&gt; <i>implementation-defined-1</i> mem_fn(R (T::*pmf) ())</a></h4>
<p>
<b>Returns:</b> a function object <i>f</i> such that the expression
<tt><i>f(t)</i></tt> is equivalent to <tt>(t.*pmf)()</tt> when <i>t</i>
is an l-value of type <b>T</b>, <tt>(get_pointer(t)->*pmf)()</tt> otherwise.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
<h4><a name="mem_fn_2">template&lt;class R, class T&gt; <i>implementation-defined-2</i> mem_fn(R (T::*pmf) () const)</a></h4>
<p>
<b>Returns:</b> a function object <i>f</i> such that the expression
<tt><i>f(t)</i></tt> is equivalent to <tt>(t.*pmf)()</tt> when <i>t</i>
is of type <b>T <i>[</i>const<i>]</i></b>, <tt>(get_pointer(t)->*pmf)()</tt> otherwise.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
<h4><a name="mem_fn_3">template&lt;class R, class T, class A1&gt; <i>implementation-defined-3</i> mem_fn(R (T::*pmf) (A1))</a></h4>
<p>
<b>Returns:</b> a function object <i>f</i> such that the expression
<tt><i>f(t, a1)</i></tt> is equivalent to <tt>(t.*pmf)(a1)</tt> when <i>t</i>
is an l-value of type <b>T</b>, <tt>(get_pointer(t)->*pmf)(a1)</tt> otherwise.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
<h4><a name="mem_fn_4">template&lt;class R, class T, class A1&gt; <i>implementation-defined-4</i> mem_fn(R (T::*pmf) (A1) const)</a></h4>
<p>
<b>Returns:</b> a function object <i>f</i> such that the expression
<tt><i>f(t, a1)</i></tt> is equivalent to <tt>(t.*pmf)(a1)</tt> when <i>t</i>
is of type <b>T <i>[</i>const<i>]</i></b>, <tt>(get_pointer(t)->*pmf)(a1)</tt> otherwise.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
<h4><a name="mem_fn_5">template&lt;class R, class T, class A1, class A2&gt; <i>implementation-defined-5</i> mem_fn(R (T::*pmf) (A1, A2))</a></h4>
<p>
<b>Returns:</b> a function object <i>f</i> such that the expression
<tt><i>f(t, a1, a2)</i></tt> is equivalent to <tt>(t.*pmf)(a1, a2)</tt> when <i>t</i>
is an l-value of type <b>T</b>, <tt>(get_pointer(t)->*pmf)(a1, a2)</tt> otherwise.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
<h4><a name="mem_fn_6">template&lt;class R, class T, class A1, class A2&gt; <i>implementation-defined-6</i> mem_fn(R (T::*pmf) (A1, A2) const)</a></h4>
<p>
<b>Returns:</b> a function object <i>f</i> such that the expression
<tt><i>f(t, a1, a2)</i></tt> is equivalent to <tt>(t.*pmf)(a1, a2)</tt> when <i>t</i>
is of type <b>T <i>[</i>const<i>]</i></b>, <tt>(get_pointer(t)->*pmf)(a1, a2)</tt> otherwise.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
<h2><a name="Implementation">Implementation</a></h2>
<h3><a name="Files">Files</a></h3>
<ul>
<li><a href="../../boost/mem_fn.hpp">boost/mem_fn.hpp</a> (main header)
<li><a href="../../boost/bind/mem_fn_cc.hpp">boost/bind/mem_fn_cc.hpp</a> (used by mem_fn.hpp, do not include directly)
<li><a href="../../boost/bind/mem_fn_vw.hpp">boost/bind/mem_fn_vw.hpp</a> (used by mem_fn.hpp, do not include directly)
<li><a href="../../boost/bind/mem_fn_template.hpp">boost/bind/mem_fn_template.hpp</a> (used by mem_fn.hpp, do not include directly)
<li><a href="mem_fn_test.cpp">libs/bind/mem_fn_test.cpp</a> (test)
<li><a href="mem_fn_stdcall_test.cpp">libs/bind/mem_fn_stdcall_test.cpp</a> (test for __stdcall)
<li><a href="mem_fn_void_test.cpp">libs/bind/mem_fn_void_test.cpp</a> (test for void returns)
</ul>
<h3><a name="Dependencies">Dependencies</a></h3>
<ul>
<li><a href="../config/config.htm">Boost.Config</a>
</ul>
<h3><a name="NumberOfArguments">Number of Arguments</a></h3>
<p>
This implementation supports member functions with up to eight arguments.
This is not an inherent limitation of the design, but an implementation
detail.
</p>
<h3><a name="stdcall">&quot;__stdcall&quot; Support</a></h3>
<p>
Some platforms allow several types of member functions that differ by their
<b>calling convention</b> (the rules by which the function is invoked: how
are arguments passed, how is the return value handled, and who cleans up the
stack - if any.)
</p>
<p>
For example, Windows API functions and COM interface member functions use a
calling convention known as <b>__stdcall</b>.
</p>
<p>
To use <b>mem_fn</b> with <b>__stdcall</b> member functions, <b>#define</b>
the macro <b>BOOST_MEM_FN_ENABLE_STDCALL</b> before including, directly or
indirectly, <b>&lt;boost/mem_fn.hpp&gt;</b>.
</p>
<p>
[Note: this is a non-portable extension. It is not part of the interface.]
</p>
<p>
[Note: Some compilers provide only minimal support for the <b>__stdcall</b> keyword.]
</p>
<h2><a name="Acknowledgements">Acknowledgements</a></h2>
<p>
Rene Jager's initial suggestion of using traits classes to make
<b>mem_fn</b> adapt to user-defined smart pointers inspired the
<b>get_pointer</b>-based design.
</p>
<p>
Numerous improvements were suggested during the formal review period by
Richard Crossley, Jens Maurer, Ed Brey, and others. Review manager
was Darin Adler.
</p>
<p>
Steve Anichini pointed out that COM interfaces use <b>__stdcall</b>.
</p>
<p>
Dave Abrahams modified <b>bind</b> and <b>mem_fn</b> to support void returns
on deficient compilers.
</p>
<p><br><br><br><small>Copyright &copy; 2001 by Peter Dimov and Multi Media
Ltd. Permission to copy, use, modify, sell and distribute this document is
granted provided this copyright notice appears in all copies. This document
is provided &quot;as is&quot; without express or implied warranty, and with
no claim as to its suitability for any purpose.</small></p>
</body>
<h3><a name="CommonRequirements">Common requirements</a></h3>
<p>
All <tt><i>unspecified-N</i></tt> types mentioned in the Synopsis are <b>CopyConstructible</b>
and <b>Assignable</b>. Their copy constructors and assignment operators do not
throw exceptions. <tt><i>unspecified-N</i>::result_type</tt> is defined as the
return type of the member function pointer passed as an argument to <b>mem_fn</b>
(<b>R</b> in the Synopsis.) <tt><i>unspecified-2-1</i>::result_type</tt> is
defined as <tt>R</tt>.
</p>
<h3><a name="get_pointer">get_pointer</a></h3>
<h4><a name="get_pointer_1">template&lt;class T&gt; T * get_pointer(T * p)</a></h4>
<blockquote>
<p>
<b>Returns:</b> <tt>p</tt>.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
</blockquote>
<h3><a name="mem_fn">mem_fn</a></h3>
<h4><a name="mem_fn_1">template&lt;class R, class T&gt; <i>unspecified-1</i> mem_fn(R
(T::*pmf) ())</a></h4>
<blockquote>
<p>
<b>Returns:</b> a function object <i>f</i> such that the expression <tt><i>f(t)</i></tt>
is equivalent to <tt>(t.*pmf)()</tt> when <i>t</i> is an l-value of type <STRONG>T </STRONG>
or derived, <tt>(get_pointer(t)-&gt;*pmf)()</tt> otherwise.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
</blockquote>
<h4><a name="mem_fn_2">template&lt;class R, class T&gt; <i>unspecified-2</i> mem_fn(R
(T::*pmf) () const)</a></h4>
<blockquote>
<p>
<b>Returns:</b> a function object <i>f</i> such that the expression <tt><i>f(t)</i></tt>
is equivalent to <tt>(t.*pmf)()</tt> when <i>t</i> is of type <STRONG>T</STRONG>
<EM>[const]<STRONG> </STRONG></EM>or derived, <tt>(get_pointer(t)-&gt;*pmf)()</tt>
otherwise.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
</blockquote>
<h4><a name="mem_fn_2_1">template&lt;class R, class T&gt; <i>unspecified-2-1</i> mem_fn(R
T::*pm)</a></h4>
<blockquote>
<p>
<b>Returns:</b> a function object <i>f</i> such that the expression <tt><i>f(t)</i></tt>
is equivalent to <tt>t.*pm</tt> when <i>t</i> is of type <STRONG>T</STRONG> <EM>[const]<STRONG>
</STRONG></EM>or derived, <tt>get_pointer(t)-&gt;*pm</tt> otherwise.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
</blockquote>
<h4><a name="mem_fn_3">template&lt;class R, class T, class A1&gt; <i>unspecified-3</i> mem_fn(R
(T::*pmf) (A1))</a></h4>
<blockquote>
<p>
<b>Returns:</b> a function object <i>f</i> such that the expression <tt><i>f(t, a1)</i></tt>
is equivalent to <tt>(t.*pmf)(a1)</tt> when <i>t</i> is an l-value of type <STRONG>T
</STRONG>or derived, <tt>(get_pointer(t)-&gt;*pmf)(a1)</tt> otherwise.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
</blockquote>
<h4><a name="mem_fn_4">template&lt;class R, class T, class A1&gt; <i>unspecified-4</i> mem_fn(R
(T::*pmf) (A1) const)</a></h4>
<blockquote>
<p>
<b>Returns:</b> a function object <i>f</i> such that the expression <tt><i>f(t, a1)</i></tt>
is equivalent to <tt>(t.*pmf)(a1)</tt> when <i>t</i> is of type <STRONG>T</STRONG>
<EM>[const]<STRONG> </STRONG></EM>or derived, <tt>(get_pointer(t)-&gt;*pmf)(a1)</tt>
otherwise.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
</blockquote>
<h4><a name="mem_fn_5">template&lt;class R, class T, class A1, class A2&gt; <i>unspecified-5</i>
mem_fn(R (T::*pmf) (A1, A2))</a></h4>
<blockquote>
<p>
<b>Returns:</b> a function object <i>f</i> such that the expression <tt><i>f(t, a1, a2)</i></tt>
is equivalent to <tt>(t.*pmf)(a1, a2)</tt> when <i>t</i> is an l-value of type <STRONG>
T</STRONG> or derived, <tt>(get_pointer(t)-&gt;*pmf)(a1, a2)</tt> otherwise.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
</blockquote>
<h4><a name="mem_fn_6">template&lt;class R, class T, class A1, class A2&gt; <i>unspecified-6</i>
mem_fn(R (T::*pmf) (A1, A2) const)</a></h4>
<blockquote>
<p>
<b>Returns:</b> a function object <i>f</i> such that the expression <tt><i>f(t, a1, a2)</i></tt>
is equivalent to <tt>(t.*pmf)(a1, a2)</tt> when <i>t</i> is of type <STRONG>T</STRONG>
<EM>[const]</EM> or derived, <tt>(get_pointer(t)-&gt;*pmf)(a1, a2)</tt> otherwise.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
</blockquote>
<h2><a name="Implementation">Implementation</a></h2>
<h3><a name="Files">Files</a></h3>
<ul>
<li>
<a href="../../boost/mem_fn.hpp">boost/mem_fn.hpp</a>
(main header)
<li>
<a href="../../boost/bind/mem_fn_cc.hpp">boost/bind/mem_fn_cc.hpp</a>
(used by mem_fn.hpp, do not include directly)
<li>
<a href="../../boost/bind/mem_fn_vw.hpp">boost/bind/mem_fn_vw.hpp</a>
(used by mem_fn.hpp, do not include directly)
<li>
<a href="../../boost/bind/mem_fn_template.hpp">boost/bind/mem_fn_template.hpp</a>
(used by mem_fn.hpp, do not include directly)
<li>
<a href="test/mem_fn_test.cpp">libs/bind/test/mem_fn_test.cpp</a>
(test)
<li>
<a href="test/mem_fn_derived_test.cpp">libs/bind/test/mem_fn_derived_test.cpp</a>
(test with derived objects)
<li>
<a href="test/mem_fn_fastcall_test.cpp">libs/bind/test/mem_fn_fastcall_test.cpp</a>
(test for __fastcall)
<li>
<a href="test/mem_fn_stdcall_test.cpp">libs/bind/test/mem_fn_stdcall_test.cpp</a>
(test for __stdcall)
<li>
<a href="test/mem_fn_void_test.cpp">libs/bind/test/mem_fn_void_test.cpp</a> (test
for void returns)</li>
</ul>
<h3><a name="Dependencies">Dependencies</a></h3>
<ul>
<li>
<a href="../config/config.htm">Boost.Config</a></li>
</ul>
<h3><a name="NumberOfArguments">Number of Arguments</a></h3>
<p>
This implementation supports member functions with up to eight arguments. This
is not an inherent limitation of the design, but an implementation detail.
</p>
<h3><a name="stdcall">"__stdcall", "__cdecl" and "__fastcall" Support</a></h3>
<p>
Some platforms allow several types of member functions that differ by their <b>calling
convention</b> (the rules by which the function is invoked: how are
arguments passed, how is the return value handled, and who cleans up the stack
- if any.)
</p>
<p>
For example, Windows API functions and COM interface member functions use a
calling convention known as <b>__stdcall</b>. Borland VCL components use <STRONG>__fastcall</STRONG>. UDK, the component model of
OpenOffice.org, uses <STRONG>__cdecl</STRONG>.
</p>
<p>
To use <b>mem_fn</b> with <b>__stdcall</b> member functions, <b>#define</b> the
macro <b>BOOST_MEM_FN_ENABLE_STDCALL</b> before including, directly or
indirectly, <b>&lt;boost/mem_fn.hpp&gt;</b>.
</p>
<P>To use <B>mem_fn</B> with <B>__fastcall</B> member functions, <B>#define</B> the
macro <B>BOOST_MEM_FN_ENABLE_FASTCALL</B> before
including <B>&lt;boost/mem_fn.hpp&gt;</B>.
</P>
<P>To use <B>mem_fn</B> with <B>__cdecl</B> member functions, <B>#define</B> the
macro <B>BOOST_MEM_FN_ENABLE_CDECL</B> before including
<B>&lt;boost/mem_fn.hpp&gt;</B>. </P>
<P><STRONG>It is best to define these macros in the project options, via -D
on the command line, or as the first line in the translation unit (.cpp file)
where mem_fn is used.</STRONG> Not following this rule can lead to obscure
errors when a header includes mem_fn.hpp before the macro has been defined.</P>
<P>[Note: this is a non-portable extension. It is not part of the interface.]
</P>
<p>
[Note: Some compilers provide only minimal support for the <b>__stdcall</b> keyword.]
</p>
<h2><a name="Acknowledgements">Acknowledgements</a></h2>
<p>
Rene Jager's initial suggestion of using traits classes to make <b>mem_fn</b> adapt
to user-defined smart pointers inspired the <b>get_pointer</b>-based design.
</p>
<p>
Numerous improvements were suggested during the formal review period by Richard
Crossley, Jens Maurer, Ed Brey, and others. Review manager was Darin Adler.
</p>
<p>
Steve Anichini pointed out that COM interfaces use <b>__stdcall</b>.
</p>
<p>
Dave Abrahams modified <b>bind</b> and <b>mem_fn</b> to support void returns on
deficient compilers.
</p>
<p>Daniel Boelzle pointed out that UDK uses <STRONG>__cdecl</STRONG>.<br>
<br>
<br>
<small>Copyright © 2001, 2002 by Peter Dimov and Multi Media Ltd. Copyright 2003-2005 Peter Dimov. Permission
to copy, use, modify, sell and distribute this document is granted provided
this copyright notice appears in all copies. This document is provided "as is"
without express or implied warranty, and with no claim as to its suitability
for any purpose.</small></p>
</body>
</html>

209
ref.html
View File

@@ -1,210 +1,9 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Boost: ref.hpp documentation</title>
<meta http-equiv="refresh" content="0; URL=../../doc/html/ref.html">
</head>
<body bgcolor="White">
<table border="0" width="100%">
<tr>
<td width="277">
<img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" width="277" height="86">
</td>
<td align="center">
<table border="0">
<tr><td nowrap><h1>ref.hpp</h1></td></tr>
<tr><td align="right" nowrap><small>&nbsp;1.00.0004 (2002-01-27)</small></td></tr>
</table>
</td>
</tr>
<tr>
<td colspan="2" height="64">&nbsp;</td>
</tr>
</table>
<h2>Files</h2>
<ul>
<li><a href="../../boost/ref.hpp">ref.hpp</a>
</ul>
<h2>Purpose</h2>
<p>
The header <a href="../../boost/ref.hpp">boost/ref.hpp</a> defines the class template
<b>boost::reference_wrapper&lt;T&gt;</b>, the two functions <b>boost::ref</b> and
<b>boost::cref</b> that return instances of
<b>boost::reference_wrapper&lt;T&gt;</b>, and the two traits classes <b>boost::is_reference_wrapper&lt;T&gt;</b> and <b>boost::unwrap_reference&lt;T&gt;</b>.
</p>
<p>
The purpose of <b>boost::reference_wrapper&lt;T&gt;</b> is to contain a reference to
an object of type <b>T</b>. It is primarily used to "feed" references to
function templates (algorithms) that take their parameter by value.
</p>
<p>
To support this usage, <b>boost::reference_wrapper&lt;T&gt;</b> provides an implicit
conversion to <b>T &amp;</b>. This usually allows the function templates to
work on references unmodified.
</p>
<p>
<b>boost::reference_wrapper&lt;T&gt;</b> is both <b>CopyConstructible</b> and
<b>Assignable</b> (ordinary references are not <b>Assignable</b>).
</p>
<p>
The expression <b>boost::ref(x)</b> returns a <b>boost::reference_wrapper&lt;X&gt;(x)</b>
where <b>X</b> is the type of <b>x</b>. Similarly, <b>boost::cref(x)</b>
returns a <b>boost::reference_wrapper&lt;X const&gt;(x)</b>.
</p>
<p>The expression <b>boost::is_reference_wrapper&lt;T&gt;::value</b> is
<b>true</b> if <b>T</b> is a
<b>reference_wrapper</b>, and <b>false</b> otherwise.
<p>The type-expression <b>boost::unwrap_reference&lt;T&gt;::type</b>
is <b>T::type</b> if <b>T</b> is a
<b>reference_wrapper</b>, <b>T</b> otherwise.
<h2>Interface</h2>
<h3>Synopsis</h3>
<pre>
namespace boost
{
template&lt;class T&gt; class <a href="#reference_wrapper">reference_wrapper</a>;
template&lt;class T&gt; reference_wrapper&lt;T&gt; <a href="#ref">ref</a>(T &amp; t);
template&lt;class T&gt; reference_wrapper&lt;T const&gt; <a href="#cref">cref</a>(T const &amp; t);
template&lt;class T&gt; class is_reference_wrapper&lt;T const&gt;;
template&lt;class T&gt; class unwrap_reference&lt;T const&gt;;
}
</pre>
<h3><a name="reference_wrapper">reference_wrapper</a></h3>
<pre>
template&lt;class T&gt; class reference_wrapper
{
public:
typedef T type;
explicit <a href="#rt_construct">reference_wrapper</a>(T &amp; t);
<a href="#rt_operator">operator T &amp;</a> () const;
T &amp; <a href="#rt_get">get</a>() const;
};
</pre>
<h4><a name="rt_construct">explicit reference_wrapper(T &amp; t)</a></h4>
<blockquote>
<p>
<b>Effects:</b> Constructs a <b>reference_wrapper</b> object that stores a reference to <b>t</b>.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
</blockquote>
<h4><a name="rt_operator">operator T &amp; () const</a></h4>
<blockquote>
<p>
<b>Returns:</b> the stored reference.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
</blockquote>
<h4><a name="rt_get">T &amp; get() const</a></h4>
<blockquote>
<p>
<b>Returns:</b> the stored reference.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
</blockquote>
<h3><a name="ref">ref</a></h3>
<pre>
template&lt;class T&gt; reference_wrapper&lt;T&gt; ref(T &amp; t);
</pre>
<blockquote>
<p>
<b>Returns:</b> <tt>reference_wrapper&lt;T&gt;(t)</tt>.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
</blockquote>
<h3><a name="cref">cref</a></h3>
<pre>
template&lt;class T&gt; reference_wrapper&lt;T const&gt; cref(T const &amp; t);
</pre>
<blockquote>
<p>
<b>Returns:</b> <tt>reference_wrapper&lt;T const&gt;(t)</tt>.
</p>
<p>
<b>Throws:</b> Nothing.
</p>
</blockquote>
<h3><a name="is_reference_wrapper">is_reference_wrapper</a></h3>
<pre>
template&lt;class T&gt; class is_reference_wrapper&lt;T const&gt;
{
public:
static bool value = <i>unspecified</i>;
};
</pre>
Value is <b>true</b> iff <tt>T</tt> is a specialization of <tt>reference_wrapper</tt>.
<h3><a name="unwrap_reference">unwrap_reference</a></h3>
<pre>
template&lt;class T&gt; class unwrap_reference&lt;T const&gt;
{
public:
typedef <i>unspecified</i> type;
};
</pre>
<tt>type</tt> is equivalent to <tt>T::type</tt> if <tt>T</tt> is a specialization of <tt>reference_wrapper</tt>. Otherwise <tt>type</tt> is equivalent to <tt>T</tt>.
<h2>Acknowledgements</h2>
<p>
<b>ref</b> and <b>cref</b> were originally part of the Boost.Tuple
library by <a href="../../people/jaakko_jarvi.htm"> Jaakko
J&auml;rvi</a>. They were "promoted to <b>boost::</b> status" by <a
href="../../people/peter_dimov.htm">Peter Dimov</a> because they are
generally useful. <a href="../../people/doug_gregor.html">Douglas
Gregor</a> and <a href="../../people/dave_abrahams.htm">Dave
Abrahams</a> contributed <tt>is_reference_wrapper</tt> and
<tt>unwrap_reference</tt>.
</p>
<p><br><br><br><small>Copyright &copy; 2001 by Peter Dimov and Multi Media
Ltd. Permission to copy, use, modify, sell and distribute this document is
granted provided this copyright notice appears in all copies. This document
is provided &quot;as is&quot; without express or implied warranty, and with
no claim as to its suitability for any purpose.</small></p>
<body>
Automatic redirection failed, please go to
<a href="../../doc/html/ref.html">../../doc/html/ref.html</a>
</body>
</html>

37
test/Jamfile Normal file
View File

@@ -0,0 +1,37 @@
# Boost.Bind Library test Jamfile
#
# Copyright (c) 2003-2005 Peter Dimov
#
# Permission to copy, use, modify, sell and distribute this software
# is granted provided this copyright notice appears in all copies.
# This software is provided "as is" without express or implied
# warranty, and with no claim as to its suitability for any purpose.
subproject libs/bind/test ;
# bring in rules for testing
import testing ;
# Make tests run by default.
DEPENDS all : bind ;
{
test-suite "bind"
: [ run bind_test.cpp ]
[ run bind_dm_test.cpp ]
[ run bind_eq_test.cpp ]
[ run bind_const_test.cpp ]
[ run bind_cv_test.cpp ]
[ run bind_stateful_test.cpp ]
[ run bind_dm2_test.cpp ]
[ run bind_not_test.cpp ]
[ run bind_rel_test.cpp ]
[ run bind_function_test.cpp ]
[ run bind_lookup_problem_test.cpp ]
[ run mem_fn_test.cpp ]
[ run mem_fn_void_test.cpp ]
[ run mem_fn_derived_test.cpp ]
[ run mem_fn_eq_test.cpp ]
[ run mem_fn_dm_test.cpp ]
;
}

30
test/Jamfile.v2 Normal file
View File

@@ -0,0 +1,30 @@
# Boost.Bind Library test Jamfile
#
# Copyright (c) 2003-2005 Peter Dimov
#
# Permission to copy, use, modify, sell and distribute this software
# is granted provided this copyright notice appears in all copies.
# This software is provided "as is" without express or implied
# warranty, and with no claim as to its suitability for any purpose.
# bring in rules for testing
import testing ;
test-suite "bind"
: [ run bind_test.cpp ]
[ run bind_dm_test.cpp ]
[ run bind_eq_test.cpp ]
[ run bind_const_test.cpp ]
[ run bind_cv_test.cpp ]
[ run bind_stateful_test.cpp ]
[ run bind_dm2_test.cpp ]
[ run bind_not_test.cpp ]
[ run bind_rel_test.cpp ]
[ run bind_function_test.cpp ]
[ run bind_lookup_problem_test.cpp ]
[ run mem_fn_test.cpp ]
[ run mem_fn_void_test.cpp ]
[ run mem_fn_derived_test.cpp ]
[ run mem_fn_eq_test.cpp ]
[ run mem_fn_dm_test.cpp ]
;

164
test/bind_cdecl_mf_test.cpp Normal file
View File

@@ -0,0 +1,164 @@
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
//
// bind_cdecl_mf_test.cpp - test for bind.hpp + __cdecl (member functions)
//
// Copyright (c) 2005 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#define BOOST_MEM_FN_ENABLE_CDECL
#include <boost/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
struct X
{
mutable unsigned int hash;
X(): hash(0) {}
int __cdecl f0() { f1(17); return 0; }
int __cdecl g0() const { g1(17); return 0; }
int __cdecl f1(int a1) { hash = (hash * 17041 + a1) % 32768; return 0; }
int __cdecl g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
int __cdecl f2(int a1, int a2) { f1(a1); f1(a2); return 0; }
int __cdecl g2(int a1, int a2) const { g1(a1); g1(a2); return 0; }
int __cdecl f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); return 0; }
int __cdecl g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); return 0; }
int __cdecl f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); return 0; }
int __cdecl g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); return 0; }
int __cdecl f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); return 0; }
int __cdecl g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); return 0; }
int __cdecl f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); return 0; }
int __cdecl g6(int a1, int a2, int a3, int a4, int a5, int a6) const { g5(a1, a2, a3, a4, a5); g1(a6); return 0; }
int __cdecl f7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) { f6(a1, a2, a3, a4, a5, a6); f1(a7); return 0; }
int __cdecl g7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) const { g6(a1, a2, a3, a4, a5, a6); g1(a7); return 0; }
int __cdecl f8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) { f7(a1, a2, a3, a4, a5, a6, a7); f1(a8); return 0; }
int __cdecl g8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) const { g7(a1, a2, a3, a4, a5, a6, a7); g1(a8); return 0; }
};
void member_function_test()
{
using namespace boost;
X x;
// 0
bind(&X::f0, &x)();
bind(&X::f0, ref(x))();
bind(&X::g0, &x)();
bind(&X::g0, x)();
bind(&X::g0, ref(x))();
// 1
bind(&X::f1, &x, 1)();
bind(&X::f1, ref(x), 1)();
bind(&X::g1, &x, 1)();
bind(&X::g1, x, 1)();
bind(&X::g1, ref(x), 1)();
// 2
bind(&X::f2, &x, 1, 2)();
bind(&X::f2, ref(x), 1, 2)();
bind(&X::g2, &x, 1, 2)();
bind(&X::g2, x, 1, 2)();
bind(&X::g2, ref(x), 1, 2)();
// 3
bind(&X::f3, &x, 1, 2, 3)();
bind(&X::f3, ref(x), 1, 2, 3)();
bind(&X::g3, &x, 1, 2, 3)();
bind(&X::g3, x, 1, 2, 3)();
bind(&X::g3, ref(x), 1, 2, 3)();
// 4
bind(&X::f4, &x, 1, 2, 3, 4)();
bind(&X::f4, ref(x), 1, 2, 3, 4)();
bind(&X::g4, &x, 1, 2, 3, 4)();
bind(&X::g4, x, 1, 2, 3, 4)();
bind(&X::g4, ref(x), 1, 2, 3, 4)();
// 5
bind(&X::f5, &x, 1, 2, 3, 4, 5)();
bind(&X::f5, ref(x), 1, 2, 3, 4, 5)();
bind(&X::g5, &x, 1, 2, 3, 4, 5)();
bind(&X::g5, x, 1, 2, 3, 4, 5)();
bind(&X::g5, ref(x), 1, 2, 3, 4, 5)();
// 6
bind(&X::f6, &x, 1, 2, 3, 4, 5, 6)();
bind(&X::f6, ref(x), 1, 2, 3, 4, 5, 6)();
bind(&X::g6, &x, 1, 2, 3, 4, 5, 6)();
bind(&X::g6, x, 1, 2, 3, 4, 5, 6)();
bind(&X::g6, ref(x), 1, 2, 3, 4, 5, 6)();
// 7
bind(&X::f7, &x, 1, 2, 3, 4, 5, 6, 7)();
bind(&X::f7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
bind(&X::g7, &x, 1, 2, 3, 4, 5, 6, 7)();
bind(&X::g7, x, 1, 2, 3, 4, 5, 6, 7)();
bind(&X::g7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
// 8
bind(&X::f8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&X::f8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&X::g8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&X::g8, x, 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&X::g8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
BOOST_TEST( x.hash == 23558 );
}
int main()
{
member_function_test();
return boost::report_errors();
}

184
test/bind_const_test.cpp Normal file
View File

@@ -0,0 +1,184 @@
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
//
// bind_const_test.cpp - test const bind objects
//
// Copyright (c) 2001-2004 Peter Dimov and Multi Media Ltd.
// Copyright (c) 2001 David Abrahams
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/bind.hpp>
#include <boost/ref.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
//
long f_0()
{
return 17041L;
}
long f_1(long a)
{
return a;
}
long f_2(long a, long b)
{
return a + 10 * b;
}
long f_3(long a, long b, long c)
{
return a + 10 * b + 100 * c;
}
long f_4(long a, long b, long c, long d)
{
return a + 10 * b + 100 * c + 1000 * d;
}
long f_5(long a, long b, long c, long d, long e)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e;
}
long f_6(long a, long b, long c, long d, long e, long f)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f;
}
long f_7(long a, long b, long c, long d, long e, long f, long g)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g;
}
long f_8(long a, long b, long c, long d, long e, long f, long g, long h)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h;
}
long f_9(long a, long b, long c, long d, long e, long f, long g, long h, long i)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
}
long global_result;
void fv_0()
{
global_result = 17041L;
}
void fv_1(long a)
{
global_result = a;
}
void fv_2(long a, long b)
{
global_result = a + 10 * b;
}
void fv_3(long a, long b, long c)
{
global_result = a + 10 * b + 100 * c;
}
void fv_4(long a, long b, long c, long d)
{
global_result = a + 10 * b + 100 * c + 1000 * d;
}
void fv_5(long a, long b, long c, long d, long e)
{
global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e;
}
void fv_6(long a, long b, long c, long d, long e, long f)
{
global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f;
}
void fv_7(long a, long b, long c, long d, long e, long f, long g)
{
global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g;
}
void fv_8(long a, long b, long c, long d, long e, long f, long g, long h)
{
global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h;
}
void fv_9(long a, long b, long c, long d, long e, long f, long g, long h, long i)
{
global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
}
template<class F, class A> long test(F const & f, A const & a)
{
return f(a);
}
template<class F, class A> long testv(F const & f, A const & a)
{
f(a);
return global_result;
}
void function_test()
{
using namespace boost;
int const i = 1;
BOOST_TEST( test( bind(f_0), i ) == 17041L );
BOOST_TEST( test( bind(f_1, _1), i ) == 1L );
BOOST_TEST( test( bind(f_2, _1, 2), i ) == 21L );
BOOST_TEST( test( bind(f_3, _1, 2, 3), i ) == 321L );
BOOST_TEST( test( bind(f_4, _1, 2, 3, 4), i ) == 4321L );
BOOST_TEST( test( bind(f_5, _1, 2, 3, 4, 5), i ) == 54321L );
BOOST_TEST( test( bind(f_6, _1, 2, 3, 4, 5, 6), i ) == 654321L );
BOOST_TEST( test( bind(f_7, _1, 2, 3, 4, 5, 6, 7), i ) == 7654321L );
BOOST_TEST( test( bind(f_8, _1, 2, 3, 4, 5, 6, 7, 8), i ) == 87654321L );
BOOST_TEST( test( bind(f_9, _1, 2, 3, 4, 5, 6, 7, 8, 9), i ) == 987654321L );
BOOST_TEST( testv( bind(fv_0), i ) == 17041L );
BOOST_TEST( testv( bind(fv_1, _1), i ) == 1L );
BOOST_TEST( testv( bind(fv_2, _1, 2), i ) == 21L );
BOOST_TEST( testv( bind(fv_3, _1, 2, 3), i ) == 321L );
BOOST_TEST( testv( bind(fv_4, _1, 2, 3, 4), i ) == 4321L );
BOOST_TEST( testv( bind(fv_5, _1, 2, 3, 4, 5), i ) == 54321L );
BOOST_TEST( testv( bind(fv_6, _1, 2, 3, 4, 5, 6), i ) == 654321L );
BOOST_TEST( testv( bind(fv_7, _1, 2, 3, 4, 5, 6, 7), i ) == 7654321L );
BOOST_TEST( testv( bind(fv_8, _1, 2, 3, 4, 5, 6, 7, 8), i ) == 87654321L );
BOOST_TEST( testv( bind(fv_9, _1, 2, 3, 4, 5, 6, 7, 8, 9), i ) == 987654321L );
}
int main()
{
function_test();
return boost::report_errors();
}

158
test/bind_cv_test.cpp Normal file
View File

@@ -0,0 +1,158 @@
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
//
// bind_cv_test.cpp
//
// Copyright (c) 2004 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
struct X
{
int operator()()
{
return 17041;
}
int operator()() const
{
return -17041;
}
int operator()(int x1)
{
return x1;
}
int operator()(int x1) const
{
return -x1;
}
int operator()(int x1, int x2)
{
return x1+x2;
}
int operator()(int x1, int x2) const
{
return -(x1+x2);
}
int operator()(int x1, int x2, int x3)
{
return x1+x2+x3;
}
int operator()(int x1, int x2, int x3) const
{
return -(x1+x2+x3);
}
int operator()(int x1, int x2, int x3, int x4)
{
return x1+x2+x3+x4;
}
int operator()(int x1, int x2, int x3, int x4) const
{
return -(x1+x2+x3+x4);
}
int operator()(int x1, int x2, int x3, int x4, int x5)
{
return x1+x2+x3+x4+x5;
}
int operator()(int x1, int x2, int x3, int x4, int x5) const
{
return -(x1+x2+x3+x4+x5);
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6)
{
return x1+x2+x3+x4+x5+x6;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6) const
{
return -(x1+x2+x3+x4+x5+x6);
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7)
{
return x1+x2+x3+x4+x5+x6+x7;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7) const
{
return -(x1+x2+x3+x4+x5+x6+x7);
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8)
{
return x1+x2+x3+x4+x5+x6+x7+x8;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8) const
{
return -(x1+x2+x3+x4+x5+x6+x7+x8);
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9)
{
return x1+x2+x3+x4+x5+x6+x7+x8+x9;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9) const
{
return -(x1+x2+x3+x4+x5+x6+x7+x8+x9);
}
};
template<class F> void test(F f, int r)
{
F const & cf = f;
BOOST_TEST( cf() == -r );
BOOST_TEST( f() == r );
}
int main()
{
test( boost::bind<int>( X() ), 17041 );
test( boost::bind<int>( X(), 1 ), 1 );
test( boost::bind<int>( X(), 1, 2 ), 1+2 );
test( boost::bind<int>( X(), 1, 2, 3 ), 1+2+3 );
test( boost::bind<int>( X(), 1, 2, 3, 4 ), 1+2+3+4 );
test( boost::bind<int>( X(), 1, 2, 3, 4, 5 ), 1+2+3+4+5 );
test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6 ), 1+2+3+4+5+6 );
test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6, 7 ), 1+2+3+4+5+6+7 );
test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6, 7, 8 ), 1+2+3+4+5+6+7+8 );
test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6, 7, 8, 9 ), 1+2+3+4+5+6+7+8+9 );
return boost::report_errors();
}

70
test/bind_dm2_test.cpp Normal file
View File

@@ -0,0 +1,70 @@
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
//
// bind_dm2_test.cpp - data members, advanced uses
//
// Copyright (c) 2005 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#include <string>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
struct X
{
int m;
};
struct Y
{
char m[ 64 ];
};
int main()
{
X x = { 0 };
X * px = &x;
boost::bind< int& >( &X::m, _1 )( px ) = 42;
BOOST_TEST( x.m == 42 );
boost::bind< int& >( &X::m, boost::ref(x) )() = 17041;
BOOST_TEST( x.m == 17041 );
X const * pcx = &x;
BOOST_TEST( boost::bind< long >( &X::m, _1 )( pcx ) == 17041L );
BOOST_TEST( boost::bind< long >( &X::m, pcx )() == 17041L );
Y y = { "test" };
std::string v( "test" );
BOOST_TEST( boost::bind< char const* >( &Y::m, &y )() == v );
BOOST_TEST( boost::bind< std::string >( &Y::m, &y )() == v );
return boost::report_errors();
}

73
test/bind_dm_test.cpp Normal file
View File

@@ -0,0 +1,73 @@
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
//
// bind_dm_test.cpp - data members
//
// Copyright (c) 2005 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
struct X
{
int m;
};
X f( int v )
{
X r = { v };
return r;
}
int main()
{
X x = { 17041 };
X * px = &x;
BOOST_TEST( boost::bind( &X::m, _1 )( x ) == 17041 );
BOOST_TEST( boost::bind( &X::m, _1 )( px ) == 17041 );
BOOST_TEST( boost::bind( &X::m, x )() == 17041 );
BOOST_TEST( boost::bind( &X::m, px )() == 17041 );
BOOST_TEST( boost::bind( &X::m, boost::ref(x) )() == 17041 );
X const cx = x;
X const * pcx = &cx;
BOOST_TEST( boost::bind( &X::m, _1 )( cx ) == 17041 );
BOOST_TEST( boost::bind( &X::m, _1 )( pcx ) == 17041 );
BOOST_TEST( boost::bind( &X::m, cx )() == 17041 );
BOOST_TEST( boost::bind( &X::m, pcx )() == 17041 );
BOOST_TEST( boost::bind( &X::m, boost::ref(cx) )() == 17041 );
int const v = 42;
BOOST_TEST( boost::bind( &X::m, boost::bind( f, _1 ) )( v ) == v );
return boost::report_errors();
}

427
test/bind_eq_test.cpp Normal file
View File

@@ -0,0 +1,427 @@
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
//
// bind_eq_test.cpp - boost::bind equality operator
//
// Copyright (c) 2004, 2005 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/bind.hpp>
#include <boost/ref.hpp>
#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
# include <boost/function_equal.hpp>
#endif
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
struct X
{
int i_;
explicit X(int i): i_(i)
{
}
bool operator==(X const & rhs) const
{
return i_ == rhs.i_;
}
};
// f_*
int f_0()
{
return 0;
}
int f_1(X)
{
return 0;
}
int f_2(X, X)
{
return 0;
}
int f_3(X, X, X)
{
return 0;
}
int f_4(X, X, X, X)
{
return 0;
}
int f_5(X, X, X, X, X)
{
return 0;
}
int f_6(X, X, X, X, X, X)
{
return 0;
}
int f_7(X, X, X, X, X, X, X)
{
return 0;
}
int f_8(X, X, X, X, X, X, X, X)
{
return 0;
}
int f_9(X, X, X, X, X, X, X, X, X)
{
return 0;
}
// fv_*
void fv_0()
{
}
void fv_1(X)
{
}
void fv_2(X, X)
{
}
void fv_3(X, X, X)
{
}
void fv_4(X, X, X, X)
{
}
void fv_5(X, X, X, X, X)
{
}
void fv_6(X, X, X, X, X, X)
{
}
void fv_7(X, X, X, X, X, X, X)
{
}
void fv_8(X, X, X, X, X, X, X, X)
{
}
void fv_9(X, X, X, X, X, X, X, X, X)
{
}
template<class F> void test_eq(F f1, F f2)
{
#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
using boost::function_equal;
#endif
BOOST_TEST( function_equal( f1, f2 ) );
}
template<class F> void test_ne(F f1, F f2)
{
#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
using boost::function_equal;
#endif
BOOST_TEST( !function_equal( f1, f2 ) );
}
// 0
template<class F> void test_0(F f)
{
test_eq( boost::bind(f), boost::bind(f) );
}
// 1
template<class F, class V> void test_1_(F f, V v1, V v2)
{
test_eq( boost::bind(f, v1), boost::bind(f, v1) );
test_ne( boost::bind(f, v1), boost::bind(f, v2) );
}
template<class F> void test_1(F f)
{
test_eq( boost::bind(f, _1), boost::bind(f, _1) );
test_1_( f, X(1), X(2) );
X a(0), b(0);
test_1_( f, boost::ref(a), boost::ref(b) );
}
// 2
template<class F, class V> void test_2_(F f, V v1, V v2)
{
test_eq( boost::bind(f, v1, v1), boost::bind(f, v1, v1) );
test_ne( boost::bind(f, v1, v1), boost::bind(f, v1, v2) );
test_ne( boost::bind(f, v1, v1), boost::bind(f, v2, v1) );
}
template<class F> void test_2(F f)
{
test_eq( boost::bind(f, _1, _2), boost::bind(f, _1, _2) );
test_2_( f, X(1), X(2) );
X a(0), b(0);
test_2_( f, boost::ref(a), boost::ref(b) );
}
// 3
template<class F, class V> void test_3_(F f, V v1, V v2)
{
test_eq( boost::bind(f, v1, v1, v1), boost::bind(f, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1), boost::bind(f, v1, v1, v2) );
test_ne( boost::bind(f, v1, v1, v1), boost::bind(f, v1, v2, v1) );
test_ne( boost::bind(f, v1, v1, v1), boost::bind(f, v2, v1, v1) );
}
template<class F> void test_3(F f)
{
test_eq( boost::bind(f, _1, _2, _3), boost::bind(f, _1, _2, _3) );
test_3_( f, X(1), X(2) );
X a(0), b(0);
test_3_( f, boost::ref(a), boost::ref(b) );
}
// 4
template<class F, class V> void test_4_(F f, V v1, V v2)
{
test_eq( boost::bind(f, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v2) );
test_ne( boost::bind(f, v1, v1, v1, v1), boost::bind(f, v1, v1, v2, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1), boost::bind(f, v1, v2, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1), boost::bind(f, v2, v1, v1, v1) );
}
template<class F> void test_4(F f)
{
test_eq( boost::bind(f, _1, _2, _3, _4), boost::bind(f, _1, _2, _3, _4) );
test_4_( f, X(1), X(2) );
X a(0), b(0);
test_4_( f, boost::ref(a), boost::ref(b) );
}
// 5
template<class F, class V> void test_5_(F f, V v1, V v2)
{
test_eq( boost::bind(f, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v2) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v2, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v2, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1), boost::bind(f, v1, v2, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1), boost::bind(f, v2, v1, v1, v1, v1) );
}
template<class F> void test_5(F f)
{
test_eq( boost::bind(f, _1, _2, _3, _4, _5), boost::bind(f, _1, _2, _3, _4, _5) );
test_5_( f, X(1), X(2) );
X a(0), b(0);
test_5_( f, boost::ref(a), boost::ref(b) );
}
// 6
template<class F, class V> void test_6_(F f, V v1, V v2)
{
test_eq( boost::bind(f, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v2) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v2, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v2, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v2, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v2, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1), boost::bind(f, v2, v1, v1, v1, v1, v1) );
}
template<class F> void test_6(F f)
{
test_eq( boost::bind(f, _1, _2, _3, _4, _5, _6), boost::bind(f, _1, _2, _3, _4, _5, _6) );
test_6_( f, X(1), X(2) );
X a(0), b(0);
test_6_( f, boost::ref(a), boost::ref(b) );
}
// 7
template<class F, class V> void test_7_(F f, V v1, V v2)
{
test_eq( boost::bind(f, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1, v2) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v2, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v2, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v2, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v2, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v2, v1, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v2, v1, v1, v1, v1, v1, v1) );
}
template<class F> void test_7(F f)
{
test_eq( boost::bind(f, _1, _2, _3, _4, _5, _6, _7), boost::bind(f, _1, _2, _3, _4, _5, _6, _7) );
test_7_( f, X(1), X(2) );
X a(0), b(0);
test_7_( f, boost::ref(a), boost::ref(b) );
}
// 8
template<class F, class V> void test_8_(F f, V v1, V v2)
{
test_eq( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v2) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1, v2, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v2, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v2, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v2, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v2, v1, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v2, v1, v1, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v2, v1, v1, v1, v1, v1, v1, v1) );
}
template<class F> void test_8(F f)
{
test_eq( boost::bind(f, _1, _2, _3, _4, _5, _6, _7, _8), boost::bind(f, _1, _2, _3, _4, _5, _6, _7, _8) );
test_8_( f, X(1), X(2) );
X a(0), b(0);
test_8_( f, boost::ref(a), boost::ref(b) );
}
// 9
template<class F, class V> void test_9_(F f, V v1, V v2)
{
test_eq( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v2) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v2, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v1, v2, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v1, v2, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v1, v2, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v1, v2, v1, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v1, v2, v1, v1, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v1, v2, v1, v1, v1, v1, v1, v1, v1) );
test_ne( boost::bind(f, v1, v1, v1, v1, v1, v1, v1, v1, v1), boost::bind(f, v2, v1, v1, v1, v1, v1, v1, v1, v1) );
}
template<class F> void test_9(F f)
{
test_eq( boost::bind(f, _1, _2, _3, _4, _5, _6, _7, _8, _9), boost::bind(f, _1, _2, _3, _4, _5, _6, _7, _8, _9) );
test_9_( f, X(1), X(2) );
X a(0), b(0);
test_9_( f, boost::ref(a), boost::ref(b) );
}
int main()
{
// 0
test_0( f_0 );
test_0( fv_0 );
// 1
test_1( f_1 );
test_1( fv_1 );
// 2
test_2( f_2 );
test_2( fv_2 );
// 3
test_3( f_3 );
test_3( fv_3 );
// 4
test_4( f_4 );
test_4( fv_4 );
// 5
test_5( f_5 );
test_5( fv_5 );
// 6
test_6( f_6 );
test_6( fv_6 );
// 7
test_7( f_7 );
test_7( fv_7 );
// 8
test_8( f_8 );
test_8( fv_8 );
// 9
test_9( f_9 );
test_9( fv_9 );
return boost::report_errors();
}

View File

@@ -0,0 +1,164 @@
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
//
// bind_stdcall_mf_test.cpp - test for bind.hpp + __stdcall (member functions)
//
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#define BOOST_MEM_FN_ENABLE_FASTCALL
#include <boost/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
struct X
{
mutable unsigned int hash;
X(): hash(0) {}
void __fastcall f0() { f1(17); }
void __fastcall g0() const { g1(17); }
void __fastcall f1(int a1) { hash = (hash * 17041 + a1) % 32768; }
void __fastcall g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; }
void __fastcall f2(int a1, int a2) { f1(a1); f1(a2); }
void __fastcall g2(int a1, int a2) const { g1(a1); g1(a2); }
void __fastcall f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); }
void __fastcall g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); }
void __fastcall f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); }
void __fastcall g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); }
void __fastcall f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); }
void __fastcall g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); }
void __fastcall f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); }
void __fastcall g6(int a1, int a2, int a3, int a4, int a5, int a6) const { g5(a1, a2, a3, a4, a5); g1(a6); }
void __fastcall f7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) { f6(a1, a2, a3, a4, a5, a6); f1(a7); }
void __fastcall g7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) const { g6(a1, a2, a3, a4, a5, a6); g1(a7); }
void __fastcall f8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) { f7(a1, a2, a3, a4, a5, a6, a7); f1(a8); }
void __fastcall g8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) const { g7(a1, a2, a3, a4, a5, a6, a7); g1(a8); }
};
void member_function_test()
{
using namespace boost;
X x;
// 0
bind(&X::f0, &x)();
bind(&X::f0, ref(x))();
bind(&X::g0, &x)();
bind(&X::g0, x)();
bind(&X::g0, ref(x))();
// 1
bind(&X::f1, &x, 1)();
bind(&X::f1, ref(x), 1)();
bind(&X::g1, &x, 1)();
bind(&X::g1, x, 1)();
bind(&X::g1, ref(x), 1)();
// 2
bind(&X::f2, &x, 1, 2)();
bind(&X::f2, ref(x), 1, 2)();
bind(&X::g2, &x, 1, 2)();
bind(&X::g2, x, 1, 2)();
bind(&X::g2, ref(x), 1, 2)();
// 3
bind(&X::f3, &x, 1, 2, 3)();
bind(&X::f3, ref(x), 1, 2, 3)();
bind(&X::g3, &x, 1, 2, 3)();
bind(&X::g3, x, 1, 2, 3)();
bind(&X::g3, ref(x), 1, 2, 3)();
// 4
bind(&X::f4, &x, 1, 2, 3, 4)();
bind(&X::f4, ref(x), 1, 2, 3, 4)();
bind(&X::g4, &x, 1, 2, 3, 4)();
bind(&X::g4, x, 1, 2, 3, 4)();
bind(&X::g4, ref(x), 1, 2, 3, 4)();
// 5
bind(&X::f5, &x, 1, 2, 3, 4, 5)();
bind(&X::f5, ref(x), 1, 2, 3, 4, 5)();
bind(&X::g5, &x, 1, 2, 3, 4, 5)();
bind(&X::g5, x, 1, 2, 3, 4, 5)();
bind(&X::g5, ref(x), 1, 2, 3, 4, 5)();
// 6
bind(&X::f6, &x, 1, 2, 3, 4, 5, 6)();
bind(&X::f6, ref(x), 1, 2, 3, 4, 5, 6)();
bind(&X::g6, &x, 1, 2, 3, 4, 5, 6)();
bind(&X::g6, x, 1, 2, 3, 4, 5, 6)();
bind(&X::g6, ref(x), 1, 2, 3, 4, 5, 6)();
// 7
bind(&X::f7, &x, 1, 2, 3, 4, 5, 6, 7)();
bind(&X::f7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
bind(&X::g7, &x, 1, 2, 3, 4, 5, 6, 7)();
bind(&X::g7, x, 1, 2, 3, 4, 5, 6, 7)();
bind(&X::g7, ref(x), 1, 2, 3, 4, 5, 6, 7)();
// 8
bind(&X::f8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&X::f8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&X::g8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&X::g8, x, 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&X::g8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
BOOST_TEST( x.hash == 23558 );
}
int main()
{
member_function_test();
return boost::report_errors();
}

110
test/bind_fastcall_test.cpp Normal file
View File

@@ -0,0 +1,110 @@
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
//
// bind_fastcall_test.cpp - test for bind.hpp + __fastcall (free functions)
//
// Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#define BOOST_BIND_ENABLE_FASTCALL
#include <boost/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
//
long __fastcall f_0()
{
return 17041L;
}
long __fastcall f_1(long a)
{
return a;
}
long __fastcall f_2(long a, long b)
{
return a + 10 * b;
}
long __fastcall f_3(long a, long b, long c)
{
return a + 10 * b + 100 * c;
}
long __fastcall f_4(long a, long b, long c, long d)
{
return a + 10 * b + 100 * c + 1000 * d;
}
long __fastcall f_5(long a, long b, long c, long d, long e)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e;
}
long __fastcall f_6(long a, long b, long c, long d, long e, long f)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f;
}
long __fastcall f_7(long a, long b, long c, long d, long e, long f, long g)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g;
}
long __fastcall f_8(long a, long b, long c, long d, long e, long f, long g, long h)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h;
}
long __fastcall f_9(long a, long b, long c, long d, long e, long f, long g, long h, long i)
{
return a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
}
void function_test()
{
using namespace boost;
int const i = 1;
BOOST_TEST( bind(f_0)(i) == 17041L );
BOOST_TEST( bind(f_1, _1)(i) == 1L );
BOOST_TEST( bind(f_2, _1, 2)(i) == 21L );
BOOST_TEST( bind(f_3, _1, 2, 3)(i) == 321L );
BOOST_TEST( bind(f_4, _1, 2, 3, 4)(i) == 4321L );
BOOST_TEST( bind(f_5, _1, 2, 3, 4, 5)(i) == 54321L );
BOOST_TEST( bind(f_6, _1, 2, 3, 4, 5, 6)(i) == 654321L );
BOOST_TEST( bind(f_7, _1, 2, 3, 4, 5, 6, 7)(i) == 7654321L );
BOOST_TEST( bind(f_8, _1, 2, 3, 4, 5, 6, 7, 8)(i) == 87654321L );
BOOST_TEST( bind(f_9, _1, 2, 3, 4, 5, 6, 7, 8, 9)(i) == 987654321L );
}
int main()
{
function_test();
return boost::report_errors();
}

View File

@@ -0,0 +1,77 @@
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
//
// bind_function_test.cpp - function<>
//
// Copyright (c) 2005 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#include <boost/function.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/bind.hpp>
#include <boost/detail/lightweight_test.hpp>
int f( int x )
{
return x;
}
int g( int x )
{
return x + 1;
}
int main()
{
boost::function0<int> fn;
BOOST_TEST( !fn.contains( boost::bind( f, 1 ) ) );
BOOST_TEST( !fn.contains( boost::bind( f, 2 ) ) );
BOOST_TEST( !fn.contains( boost::bind( g, 1 ) ) );
fn = boost::bind( f, 1 );
BOOST_TEST( fn() == 1 );
BOOST_TEST( fn.contains( boost::bind( f, 1 ) ) );
BOOST_TEST( !fn.contains( boost::bind( f, 2 ) ) );
BOOST_TEST( !fn.contains( boost::bind( g, 1 ) ) );
fn = boost::bind( f, 2 );
BOOST_TEST( fn() == 2 );
BOOST_TEST( !fn.contains( boost::bind( f, 1 ) ) );
BOOST_TEST( fn.contains( boost::bind( f, 2 ) ) );
BOOST_TEST( !fn.contains( boost::bind( g, 1 ) ) );
fn = boost::bind( g, 1 );
BOOST_TEST( fn() == 2 );
BOOST_TEST( !fn.contains( boost::bind( f, 1 ) ) );
BOOST_TEST( !fn.contains( boost::bind( f, 2 ) ) );
BOOST_TEST( fn.contains( boost::bind( g, 1 ) ) );
return boost::report_errors();
}

View File

@@ -0,0 +1,40 @@
//
// bind_lookup_problem_test.cpp
//
// Copyright (C) Markus Schöpflin 2005.
//
// Use, modification, and distribution are subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/bind.hpp>
template<class T> void value();
void f0() { }
void f1(int) { }
void f2(int, int) { }
void f3(int, int, int) { }
void f4(int, int, int, int) { }
void f5(int, int, int, int, int) { }
void f6(int, int, int, int, int, int) { }
void f7(int, int, int, int, int, int, int) { }
void f8(int, int, int, int, int, int, int, int) { }
void f9(int, int, int, int, int, int, int, int, int) { }
int main()
{
boost::bind(f0);
boost::bind(f1, 0);
boost::bind(f2, 0, 0);
boost::bind(f3, 0, 0, 0);
boost::bind(f4, 0, 0, 0, 0);
boost::bind(f5, 0, 0, 0, 0, 0);
boost::bind(f6, 0, 0, 0, 0, 0, 0);
boost::bind(f7, 0, 0, 0, 0, 0, 0, 0);
boost::bind(f8, 0, 0, 0, 0, 0, 0, 0, 0);
boost::bind(f9, 0, 0, 0, 0, 0, 0, 0, 0, 0);
return 0;
}

57
test/bind_not_test.cpp Normal file
View File

@@ -0,0 +1,57 @@
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
//
// bind_not_test.cpp - operator!
//
// Copyright (c) 2005 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
template<class F, class A1, class R> void test( F f, A1 a1, R r )
{
BOOST_TEST( f(a1) == r );
}
bool f( bool v )
{
return v;
}
int g( int v )
{
return v;
}
int main()
{
test( !boost::bind( f, true ), 0, !f( true ) );
test( !boost::bind( g, _1 ), 5, !g( 5 ) );
test( boost::bind( f, !boost::bind( f, true ) ), 0, f( !f( true ) ) );
test( boost::bind( f, !boost::bind( f, _1 ) ), true, f( !f( true ) ) );
return boost::report_errors();
}

97
test/bind_rel_test.cpp Normal file
View File

@@ -0,0 +1,97 @@
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
//
// bind_rel_test.cpp - ==, !=, <, <=, >, >= operators
//
// Copyright (c) 2005 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
int f( int x )
{
return x + x;
}
int g( int x )
{
return 2 * x;
}
int main()
{
int x = 4;
int y = x + x;
// bind op value
BOOST_TEST( ( boost::bind( f, _1 ) == y )( x ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) != y )( x ) ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) < y )( x ) ) );
BOOST_TEST( ( boost::bind( f, _1 ) < y + 1 )( x ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) > y )( x ) ) );
BOOST_TEST( ( boost::bind( f, _1 ) > y - 1 )( x ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) <= y - 1 )( x ) ) );
BOOST_TEST( ( boost::bind( f, _1 ) <= y )( x ) );
BOOST_TEST( ( boost::bind( f, _1 ) <= y + 1 )( x ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) >= y + 1 )( x ) ) );
BOOST_TEST( ( boost::bind( f, _1 ) >= y )( x ) );
BOOST_TEST( ( boost::bind( f, _1 ) >= y - 1 )( x ) );
// bind op ref
BOOST_TEST( ( boost::bind( f, _1 ) == boost::ref( y ) )( x ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) != boost::ref( y ) )( x ) ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) < boost::ref( y ) )( x ) ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) > boost::ref( y ) )( x ) ) );
BOOST_TEST( ( boost::bind( f, _1 ) <= boost::ref( y ) )( x ) );
BOOST_TEST( ( boost::bind( f, _1 ) >= boost::ref( y ) )( x ) );
// bind op placeholder
BOOST_TEST( ( boost::bind( f, _1 ) == _2 )( x, y ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) != _2 )( x, y ) ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) < _2 )( x, y ) ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) > _2 )( x, y ) ) );
BOOST_TEST( ( boost::bind( f, _1 ) <= _2 )( x, y ) );
BOOST_TEST( ( boost::bind( f, _1 ) >= _2 )( x, y ) );
// bind op bind
// important: bind( f, _1 ) and bind( g, _1 ) have the same type
BOOST_TEST( ( boost::bind( f, _1 ) == boost::bind( g, _1 ) )( x ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) != boost::bind( g, _1 ) )( x ) ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) < boost::bind( g, _1 ) )( x ) ) );
BOOST_TEST( ( boost::bind( f, _1 ) <= boost::bind( g, _1 ) )( x ) );
BOOST_TEST( !( ( boost::bind( f, _1 ) > boost::bind( g, _1 ) )( x ) ) );
BOOST_TEST( ( boost::bind( f, _1 ) >= boost::bind( g, _1 ) )( x ) );
return boost::report_errors();
}

222
test/bind_stateful_test.cpp Normal file
View File

@@ -0,0 +1,222 @@
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
//
// bind_stateful_test.cpp
//
// Copyright (c) 2004 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/bind.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
class X
{
private:
int state_;
public:
X(): state_(0)
{
}
int state() const
{
return state_;
}
int operator()()
{
return state_ += 17041;
}
int operator()(int x1)
{
return state_ += x1;
}
int operator()(int x1, int x2)
{
return state_ += x1+x2;
}
int operator()(int x1, int x2, int x3)
{
return state_ += x1+x2+x3;
}
int operator()(int x1, int x2, int x3, int x4)
{
return state_ += x1+x2+x3+x4;
}
int operator()(int x1, int x2, int x3, int x4, int x5)
{
return state_ += x1+x2+x3+x4+x5;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6)
{
return state_ += x1+x2+x3+x4+x5+x6;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7)
{
return state_ += x1+x2+x3+x4+x5+x6+x7;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8)
{
return state_ += x1+x2+x3+x4+x5+x6+x7+x8;
}
int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9)
{
return state_ += x1+x2+x3+x4+x5+x6+x7+x8+x9;
}
};
int f0(int & state_)
{
return state_ += 17041;
}
int f1(int & state_, int x1)
{
return state_ += x1;
}
int f2(int & state_, int x1, int x2)
{
return state_ += x1+x2;
}
int f3(int & state_, int x1, int x2, int x3)
{
return state_ += x1+x2+x3;
}
int f4(int & state_, int x1, int x2, int x3, int x4)
{
return state_ += x1+x2+x3+x4;
}
int f5(int & state_, int x1, int x2, int x3, int x4, int x5)
{
return state_ += x1+x2+x3+x4+x5;
}
int f6(int & state_, int x1, int x2, int x3, int x4, int x5, int x6)
{
return state_ += x1+x2+x3+x4+x5+x6;
}
int f7(int & state_, int x1, int x2, int x3, int x4, int x5, int x6, int x7)
{
return state_ += x1+x2+x3+x4+x5+x6+x7;
}
int f8(int & state_, int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8)
{
return state_ += x1+x2+x3+x4+x5+x6+x7+x8;
}
template<class F> void test(F f, int a, int b)
{
BOOST_TEST( f() == a + b );
BOOST_TEST( f() == a + 2*b );
BOOST_TEST( f() == a + 3*b );
}
void stateful_function_object_test()
{
test( boost::bind<int>( X() ), 0, 17041 );
test( boost::bind<int>( X(), 1 ), 0, 1 );
test( boost::bind<int>( X(), 1, 2 ), 0, 1+2 );
test( boost::bind<int>( X(), 1, 2, 3 ), 0, 1+2+3 );
test( boost::bind<int>( X(), 1, 2, 3, 4 ), 0, 1+2+3+4 );
test( boost::bind<int>( X(), 1, 2, 3, 4, 5 ), 0, 1+2+3+4+5 );
test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6 ), 0, 1+2+3+4+5+6 );
test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6, 7 ), 0, 1+2+3+4+5+6+7 );
test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6, 7, 8 ), 0, 1+2+3+4+5+6+7+8 );
test( boost::bind<int>( X(), 1, 2, 3, 4, 5, 6, 7, 8, 9 ), 0, 1+2+3+4+5+6+7+8+9 );
X x;
int n = x.state();
test( boost::bind<int>( boost::ref(x) ), n, 17041 );
n += 3*17041;
test( boost::bind<int>( boost::ref(x), 1 ), n, 1 );
n += 3*1;
test( boost::bind<int>( boost::ref(x), 1, 2 ), n, 1+2 );
n += 3*(1+2);
test( boost::bind<int>( boost::ref(x), 1, 2, 3 ), n, 1+2+3 );
n += 3*(1+2+3);
test( boost::bind<int>( boost::ref(x), 1, 2, 3, 4 ), n, 1+2+3+4 );
n += 3*(1+2+3+4);
test( boost::bind<int>( boost::ref(x), 1, 2, 3, 4, 5 ), n, 1+2+3+4+5 );
n += 3*(1+2+3+4+5);
test( boost::bind<int>( boost::ref(x), 1, 2, 3, 4, 5, 6 ), n, 1+2+3+4+5+6 );
n += 3*(1+2+3+4+5+6);
test( boost::bind<int>( boost::ref(x), 1, 2, 3, 4, 5, 6, 7 ), n, 1+2+3+4+5+6+7 );
n += 3*(1+2+3+4+5+6+7);
test( boost::bind<int>( boost::ref(x), 1, 2, 3, 4, 5, 6, 7, 8 ), n, 1+2+3+4+5+6+7+8 );
n += 3*(1+2+3+4+5+6+7+8);
test( boost::bind<int>( boost::ref(x), 1, 2, 3, 4, 5, 6, 7, 8, 9 ), n, 1+2+3+4+5+6+7+8+9 );
n += 3*(1+2+3+4+5+6+7+8+9);
BOOST_TEST( x.state() == n );
}
void stateful_function_test()
{
test( boost::bind( f0, 0 ), 0, 17041 );
test( boost::bind( f1, 0, 1 ), 0, 1 );
test( boost::bind( f2, 0, 1, 2 ), 0, 1+2 );
test( boost::bind( f3, 0, 1, 2, 3 ), 0, 1+2+3 );
test( boost::bind( f4, 0, 1, 2, 3, 4 ), 0, 1+2+3+4 );
test( boost::bind( f5, 0, 1, 2, 3, 4, 5 ), 0, 1+2+3+4+5 );
test( boost::bind( f6, 0, 1, 2, 3, 4, 5, 6 ), 0, 1+2+3+4+5+6 );
test( boost::bind( f7, 0, 1, 2, 3, 4, 5, 6, 7 ), 0, 1+2+3+4+5+6+7 );
test( boost::bind( f8, 0, 1, 2, 3, 4, 5, 6, 7, 8 ), 0, 1+2+3+4+5+6+7+8 );
}
int main()
{
stateful_function_object_test();
stateful_function_test();
return boost::report_errors();
}

View File

@@ -1,4 +1,6 @@
#if defined(_MSC_VER) && !defined(__ICL)
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
@@ -10,10 +12,9 @@
//
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#define BOOST_MEM_FN_ENABLE_STDCALL
@@ -30,9 +31,7 @@
#pragma warning(pop)
#endif
#define BOOST_INCLUDE_MAIN
#include <boost/test/test_tools.hpp>
#include <boost/detail/lightweight_test.hpp>
struct X
{
@@ -158,8 +157,8 @@ void member_function_test()
BOOST_TEST( x.hash == 23558 );
}
int test_main(int, char * [])
int main()
{
member_function_test();
return 0;
return boost::report_errors();
}

View File

@@ -1,4 +1,6 @@
#if defined(_MSC_VER) && !defined(__ICL)
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
@@ -10,10 +12,9 @@
//
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#define BOOST_BIND_ENABLE_STDCALL
@@ -30,8 +31,7 @@
#pragma warning(pop)
#endif
#define BOOST_INCLUDE_MAIN
#include <boost/test/test_tools.hpp>
#include <boost/detail/lightweight_test.hpp>
//
@@ -103,8 +103,8 @@ void function_test()
BOOST_TEST( bind(f_9, _1, 2, 3, 4, 5, 6, 7, 8, 9)(i) == 987654321L );
}
int test_main(int, char * [])
int main()
{
function_test();
return 0;
return boost::report_errors();
}

View File

@@ -1,4 +1,6 @@
#if defined(_MSC_VER) && !defined(__ICL)
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
@@ -8,13 +10,12 @@
//
// bind_test.cpp - monolithic test for bind.hpp
//
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
// Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
// Copyright (c) 2001 David Abrahams
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/bind.hpp>
@@ -30,9 +31,7 @@
#pragma warning(pop)
#endif
#define BOOST_INCLUDE_MAIN
#include <boost/test/test_tools.hpp>
#include <boost/detail/lightweight_test.hpp>
//
@@ -190,14 +189,33 @@ void function_object_test()
BOOST_TEST( bind<int>(Y(), i, _1)(k) == 38 );
BOOST_TEST( bind<long>(Y(), i, _1, 9)(k) == 938 );
#if !defined(__MWERKS__) || (__MWERKS__ > 0x2406) // Fails for this version of the compiler.
#if !defined(__MWERKS__) || (__MWERKS__ > 0x2407) // Fails for this version of the compiler.
global_result = 0;
bind<void>(Y(), i, _1, 9, 4)(k);
BOOST_TEST( global_result == 4938 );
#endif
}
void function_object_test2()
{
using namespace boost;
short i(6);
int const k = 3;
BOOST_TEST( bind(type<short>(), Y(), ref(i))() == 7 );
BOOST_TEST( bind(type<short>(), Y(), ref(i))() == 8 );
BOOST_TEST( bind(type<int>(), Y(), i, _1)(k) == 38 );
BOOST_TEST( bind(type<long>(), Y(), i, _1, 9)(k) == 938 );
global_result = 0;
bind(type<void>(), Y(), i, _1, 9, 4)(k);
BOOST_TEST( global_result == 4938 );
}
//
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
@@ -485,10 +503,11 @@ void nested_bind_test()
BOOST_TEST( (bind(fv_1, bind(f_0))(), (global_result == 17041L)) );
}
int test_main(int, char * [])
int main()
{
function_test();
function_object_test();
function_object_test2();
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
adaptable_function_object_test();
@@ -498,5 +517,5 @@ int test_main(int, char * [])
member_function_void_test();
nested_bind_test();
return 0;
return boost::report_errors();
}

186
test/mem_fn_cdecl_test.cpp Normal file
View File

@@ -0,0 +1,186 @@
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
//
// mem_fn_cdecl_test.cpp - a test for mem_fn.hpp + __cdecl
//
// Copyright (c) 2005 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#define BOOST_MEM_FN_ENABLE_CDECL
#include <boost/mem_fn.hpp>
#include <boost/shared_ptr.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
struct X
{
mutable unsigned int hash;
X(): hash(0) {}
int __cdecl f0() { f1(17); return 0; }
int __cdecl g0() const { g1(17); return 0; }
int __cdecl f1(int a1) { hash = (hash * 17041 + a1) % 32768; return 0; }
int __cdecl g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
int __cdecl f2(int a1, int a2) { f1(a1); f1(a2); return 0; }
int __cdecl g2(int a1, int a2) const { g1(a1); g1(a2); return 0; }
int __cdecl f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); return 0; }
int __cdecl g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); return 0; }
int __cdecl f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); return 0; }
int __cdecl g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); return 0; }
int __cdecl f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); return 0; }
int __cdecl g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); return 0; }
int __cdecl f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); return 0; }
int __cdecl g6(int a1, int a2, int a3, int a4, int a5, int a6) const { g5(a1, a2, a3, a4, a5); g1(a6); return 0; }
int __cdecl f7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) { f6(a1, a2, a3, a4, a5, a6); f1(a7); return 0; }
int __cdecl g7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) const { g6(a1, a2, a3, a4, a5, a6); g1(a7); return 0; }
int __cdecl f8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) { f7(a1, a2, a3, a4, a5, a6, a7); f1(a8); return 0; }
int __cdecl g8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) const { g7(a1, a2, a3, a4, a5, a6, a7); g1(a8); return 0; }
};
int detect_errors(bool x)
{
if(x)
{
std::cerr << "no errors detected.\n";
return 0;
}
else
{
std::cerr << "test failed.\n";
return 1;
}
}
int main()
{
using boost::mem_fn;
X x;
X const & rcx = x;
X const * pcx = &x;
boost::shared_ptr<X> sp(new X);
mem_fn(&X::f0)(x);
mem_fn(&X::f0)(&x);
mem_fn(&X::f0)(sp);
mem_fn(&X::g0)(x);
mem_fn(&X::g0)(rcx);
mem_fn(&X::g0)(&x);
mem_fn(&X::g0)(pcx);
mem_fn(&X::g0)(sp);
mem_fn(&X::f1)(x, 1);
mem_fn(&X::f1)(&x, 1);
mem_fn(&X::f1)(sp, 1);
mem_fn(&X::g1)(x, 1);
mem_fn(&X::g1)(rcx, 1);
mem_fn(&X::g1)(&x, 1);
mem_fn(&X::g1)(pcx, 1);
mem_fn(&X::g1)(sp, 1);
mem_fn(&X::f2)(x, 1, 2);
mem_fn(&X::f2)(&x, 1, 2);
mem_fn(&X::f2)(sp, 1, 2);
mem_fn(&X::g2)(x, 1, 2);
mem_fn(&X::g2)(rcx, 1, 2);
mem_fn(&X::g2)(&x, 1, 2);
mem_fn(&X::g2)(pcx, 1, 2);
mem_fn(&X::g2)(sp, 1, 2);
mem_fn(&X::f3)(x, 1, 2, 3);
mem_fn(&X::f3)(&x, 1, 2, 3);
mem_fn(&X::f3)(sp, 1, 2, 3);
mem_fn(&X::g3)(x, 1, 2, 3);
mem_fn(&X::g3)(rcx, 1, 2, 3);
mem_fn(&X::g3)(&x, 1, 2, 3);
mem_fn(&X::g3)(pcx, 1, 2, 3);
mem_fn(&X::g3)(sp, 1, 2, 3);
mem_fn(&X::f4)(x, 1, 2, 3, 4);
mem_fn(&X::f4)(&x, 1, 2, 3, 4);
mem_fn(&X::f4)(sp, 1, 2, 3, 4);
mem_fn(&X::g4)(x, 1, 2, 3, 4);
mem_fn(&X::g4)(rcx, 1, 2, 3, 4);
mem_fn(&X::g4)(&x, 1, 2, 3, 4);
mem_fn(&X::g4)(pcx, 1, 2, 3, 4);
mem_fn(&X::g4)(sp, 1, 2, 3, 4);
mem_fn(&X::f5)(x, 1, 2, 3, 4, 5);
mem_fn(&X::f5)(&x, 1, 2, 3, 4, 5);
mem_fn(&X::f5)(sp, 1, 2, 3, 4, 5);
mem_fn(&X::g5)(x, 1, 2, 3, 4, 5);
mem_fn(&X::g5)(rcx, 1, 2, 3, 4, 5);
mem_fn(&X::g5)(&x, 1, 2, 3, 4, 5);
mem_fn(&X::g5)(pcx, 1, 2, 3, 4, 5);
mem_fn(&X::g5)(sp, 1, 2, 3, 4, 5);
mem_fn(&X::f6)(x, 1, 2, 3, 4, 5, 6);
mem_fn(&X::f6)(&x, 1, 2, 3, 4, 5, 6);
mem_fn(&X::f6)(sp, 1, 2, 3, 4, 5, 6);
mem_fn(&X::g6)(x, 1, 2, 3, 4, 5, 6);
mem_fn(&X::g6)(rcx, 1, 2, 3, 4, 5, 6);
mem_fn(&X::g6)(&x, 1, 2, 3, 4, 5, 6);
mem_fn(&X::g6)(pcx, 1, 2, 3, 4, 5, 6);
mem_fn(&X::g6)(sp, 1, 2, 3, 4, 5, 6);
mem_fn(&X::f7)(x, 1, 2, 3, 4, 5, 6, 7);
mem_fn(&X::f7)(&x, 1, 2, 3, 4, 5, 6, 7);
mem_fn(&X::f7)(sp, 1, 2, 3, 4, 5, 6, 7);
mem_fn(&X::g7)(x, 1, 2, 3, 4, 5, 6, 7);
mem_fn(&X::g7)(rcx, 1, 2, 3, 4, 5, 6, 7);
mem_fn(&X::g7)(&x, 1, 2, 3, 4, 5, 6, 7);
mem_fn(&X::g7)(pcx, 1, 2, 3, 4, 5, 6, 7);
mem_fn(&X::g7)(sp, 1, 2, 3, 4, 5, 6, 7);
mem_fn(&X::f8)(x, 1, 2, 3, 4, 5, 6, 7, 8);
mem_fn(&X::f8)(&x, 1, 2, 3, 4, 5, 6, 7, 8);
mem_fn(&X::f8)(sp, 1, 2, 3, 4, 5, 6, 7, 8);
mem_fn(&X::g8)(x, 1, 2, 3, 4, 5, 6, 7, 8);
mem_fn(&X::g8)(rcx, 1, 2, 3, 4, 5, 6, 7, 8);
mem_fn(&X::g8)(&x, 1, 2, 3, 4, 5, 6, 7, 8);
mem_fn(&X::g8)(pcx, 1, 2, 3, 4, 5, 6, 7, 8);
mem_fn(&X::g8)(sp, 1, 2, 3, 4, 5, 6, 7, 8);
return detect_errors(x.hash == 17610 && sp->hash == 2155);
}

View File

@@ -1,4 +1,6 @@
#if defined(_MSC_VER) && !defined(__ICL)
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
@@ -8,12 +10,11 @@
//
// mem_fn_derived_test.cpp - tests mem_fn.hpp with derived objects
//
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
// Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/mem_fn.hpp>
@@ -183,5 +184,5 @@ int main()
mem_fn(&X::g8)(pcx, 1, 2, 3, 4, 5, 6, 7, 8);
mem_fn(&X::g8)(sp, 1, 2, 3, 4, 5, 6, 7, 8);
return detect_errors(x.hash == 17610 && sp->hash == 2155);
return detect_errors(mem_fn(&X::hash)(x) == 17610 && mem_fn(&X::hash)(sp) == 2155);
}

67
test/mem_fn_dm_test.cpp Normal file
View File

@@ -0,0 +1,67 @@
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
//
// mem_fn_dm_test.cpp - data members
//
// Copyright (c) 2005 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/mem_fn.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
struct X
{
int m;
};
int main()
{
X x = { 0 };
boost::mem_fn( &X::m )( x ) = 401;
BOOST_TEST( x.m == 401 );
BOOST_TEST( boost::mem_fn( &X::m )( x ) == 401 );
boost::mem_fn( &X::m )( &x ) = 502;
BOOST_TEST( x.m == 502 );
BOOST_TEST( boost::mem_fn( &X::m )( &x ) == 502 );
X * px = &x;
boost::mem_fn( &X::m )( px ) = 603;
BOOST_TEST( x.m == 603 );
BOOST_TEST( boost::mem_fn( &X::m )( px ) == 603 );
X const & cx = x;
X const * pcx = &x;
BOOST_TEST( boost::mem_fn( &X::m )( cx ) == 603 );
BOOST_TEST( boost::mem_fn( &X::m )( pcx ) == 603 );
return boost::report_errors();
}

300
test/mem_fn_eq_test.cpp Normal file
View File

@@ -0,0 +1,300 @@
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
//
// mem_fn_eq_test.cpp - boost::mem_fn equality operator
//
// Copyright (c) 2004 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/mem_fn.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
#include <boost/detail/lightweight_test.hpp>
struct X
{
int dm_1;
int dm_2;
// 0
int mf0_1() { return 0; }
int mf0_2() { return 0; }
int cmf0_1() const { return 0; }
int cmf0_2() const { return 0; }
void mf0v_1() {}
void mf0v_2() {}
void cmf0v_1() const {}
void cmf0v_2() const {}
// 1
int mf1_1(int) { return 0; }
int mf1_2(int) { return 0; }
int cmf1_1(int) const { return 0; }
int cmf1_2(int) const { return 0; }
void mf1v_1(int) {}
void mf1v_2(int) {}
void cmf1v_1(int) const {}
void cmf1v_2(int) const {}
// 2
int mf2_1(int, int) { return 0; }
int mf2_2(int, int) { return 0; }
int cmf2_1(int, int) const { return 0; }
int cmf2_2(int, int) const { return 0; }
void mf2v_1(int, int) {}
void mf2v_2(int, int) {}
void cmf2v_1(int, int) const {}
void cmf2v_2(int, int) const {}
// 3
int mf3_1(int, int, int) { return 0; }
int mf3_2(int, int, int) { return 0; }
int cmf3_1(int, int, int) const { return 0; }
int cmf3_2(int, int, int) const { return 0; }
void mf3v_1(int, int, int) {}
void mf3v_2(int, int, int) {}
void cmf3v_1(int, int, int) const {}
void cmf3v_2(int, int, int) const {}
// 4
int mf4_1(int, int, int, int) { return 0; }
int mf4_2(int, int, int, int) { return 0; }
int cmf4_1(int, int, int, int) const { return 0; }
int cmf4_2(int, int, int, int) const { return 0; }
void mf4v_1(int, int, int, int) {}
void mf4v_2(int, int, int, int) {}
void cmf4v_1(int, int, int, int) const {}
void cmf4v_2(int, int, int, int) const {}
// 5
int mf5_1(int, int, int, int, int) { return 0; }
int mf5_2(int, int, int, int, int) { return 0; }
int cmf5_1(int, int, int, int, int) const { return 0; }
int cmf5_2(int, int, int, int, int) const { return 0; }
void mf5v_1(int, int, int, int, int) {}
void mf5v_2(int, int, int, int, int) {}
void cmf5v_1(int, int, int, int, int) const {}
void cmf5v_2(int, int, int, int, int) const {}
// 6
int mf6_1(int, int, int, int, int, int) { return 0; }
int mf6_2(int, int, int, int, int, int) { return 0; }
int cmf6_1(int, int, int, int, int, int) const { return 0; }
int cmf6_2(int, int, int, int, int, int) const { return 0; }
void mf6v_1(int, int, int, int, int, int) {}
void mf6v_2(int, int, int, int, int, int) {}
void cmf6v_1(int, int, int, int, int, int) const {}
void cmf6v_2(int, int, int, int, int, int) const {}
// 7
int mf7_1(int, int, int, int, int, int, int) { return 0; }
int mf7_2(int, int, int, int, int, int, int) { return 0; }
int cmf7_1(int, int, int, int, int, int, int) const { return 0; }
int cmf7_2(int, int, int, int, int, int, int) const { return 0; }
void mf7v_1(int, int, int, int, int, int, int) {}
void mf7v_2(int, int, int, int, int, int, int) {}
void cmf7v_1(int, int, int, int, int, int, int) const {}
void cmf7v_2(int, int, int, int, int, int, int) const {}
// 8
int mf8_1(int, int, int, int, int, int, int, int) { return 0; }
int mf8_2(int, int, int, int, int, int, int, int) { return 0; }
int cmf8_1(int, int, int, int, int, int, int, int) const { return 0; }
int cmf8_2(int, int, int, int, int, int, int, int) const { return 0; }
void mf8v_1(int, int, int, int, int, int, int, int) {}
void mf8v_2(int, int, int, int, int, int, int, int) {}
void cmf8v_1(int, int, int, int, int, int, int, int) const {}
void cmf8v_2(int, int, int, int, int, int, int, int) const {}
};
int main()
{
BOOST_TEST( boost::mem_fn(&X::dm_1) == boost::mem_fn(&X::dm_1) );
BOOST_TEST( boost::mem_fn(&X::dm_1) != boost::mem_fn(&X::dm_2) );
// 0
BOOST_TEST( boost::mem_fn(&X::mf0_1) == boost::mem_fn(&X::mf0_1) );
BOOST_TEST( boost::mem_fn(&X::mf0_1) != boost::mem_fn(&X::mf0_2) );
BOOST_TEST( boost::mem_fn(&X::cmf0_1) == boost::mem_fn(&X::cmf0_1) );
BOOST_TEST( boost::mem_fn(&X::cmf0_1) != boost::mem_fn(&X::cmf0_2) );
BOOST_TEST( boost::mem_fn(&X::mf0v_1) == boost::mem_fn(&X::mf0v_1) );
BOOST_TEST( boost::mem_fn(&X::mf0v_1) != boost::mem_fn(&X::mf0v_2) );
BOOST_TEST( boost::mem_fn(&X::cmf0v_1) == boost::mem_fn(&X::cmf0v_1) );
BOOST_TEST( boost::mem_fn(&X::cmf0v_1) != boost::mem_fn(&X::cmf0v_2) );
// 1
BOOST_TEST( boost::mem_fn(&X::mf1_1) == boost::mem_fn(&X::mf1_1) );
BOOST_TEST( boost::mem_fn(&X::mf1_1) != boost::mem_fn(&X::mf1_2) );
BOOST_TEST( boost::mem_fn(&X::cmf1_1) == boost::mem_fn(&X::cmf1_1) );
BOOST_TEST( boost::mem_fn(&X::cmf1_1) != boost::mem_fn(&X::cmf1_2) );
BOOST_TEST( boost::mem_fn(&X::mf1v_1) == boost::mem_fn(&X::mf1v_1) );
BOOST_TEST( boost::mem_fn(&X::mf1v_1) != boost::mem_fn(&X::mf1v_2) );
BOOST_TEST( boost::mem_fn(&X::cmf1v_1) == boost::mem_fn(&X::cmf1v_1) );
BOOST_TEST( boost::mem_fn(&X::cmf1v_1) != boost::mem_fn(&X::cmf1v_2) );
// 2
BOOST_TEST( boost::mem_fn(&X::mf2_1) == boost::mem_fn(&X::mf2_1) );
BOOST_TEST( boost::mem_fn(&X::mf2_1) != boost::mem_fn(&X::mf2_2) );
BOOST_TEST( boost::mem_fn(&X::cmf2_1) == boost::mem_fn(&X::cmf2_1) );
BOOST_TEST( boost::mem_fn(&X::cmf2_1) != boost::mem_fn(&X::cmf2_2) );
BOOST_TEST( boost::mem_fn(&X::mf2v_1) == boost::mem_fn(&X::mf2v_1) );
BOOST_TEST( boost::mem_fn(&X::mf2v_1) != boost::mem_fn(&X::mf2v_2) );
BOOST_TEST( boost::mem_fn(&X::cmf2v_1) == boost::mem_fn(&X::cmf2v_1) );
BOOST_TEST( boost::mem_fn(&X::cmf2v_1) != boost::mem_fn(&X::cmf2v_2) );
// 3
BOOST_TEST( boost::mem_fn(&X::mf3_1) == boost::mem_fn(&X::mf3_1) );
BOOST_TEST( boost::mem_fn(&X::mf3_1) != boost::mem_fn(&X::mf3_2) );
BOOST_TEST( boost::mem_fn(&X::cmf3_1) == boost::mem_fn(&X::cmf3_1) );
BOOST_TEST( boost::mem_fn(&X::cmf3_1) != boost::mem_fn(&X::cmf3_2) );
BOOST_TEST( boost::mem_fn(&X::mf3v_1) == boost::mem_fn(&X::mf3v_1) );
BOOST_TEST( boost::mem_fn(&X::mf3v_1) != boost::mem_fn(&X::mf3v_2) );
BOOST_TEST( boost::mem_fn(&X::cmf3v_1) == boost::mem_fn(&X::cmf3v_1) );
BOOST_TEST( boost::mem_fn(&X::cmf3v_1) != boost::mem_fn(&X::cmf3v_2) );
// 4
BOOST_TEST( boost::mem_fn(&X::mf4_1) == boost::mem_fn(&X::mf4_1) );
BOOST_TEST( boost::mem_fn(&X::mf4_1) != boost::mem_fn(&X::mf4_2) );
BOOST_TEST( boost::mem_fn(&X::cmf4_1) == boost::mem_fn(&X::cmf4_1) );
BOOST_TEST( boost::mem_fn(&X::cmf4_1) != boost::mem_fn(&X::cmf4_2) );
BOOST_TEST( boost::mem_fn(&X::mf4v_1) == boost::mem_fn(&X::mf4v_1) );
BOOST_TEST( boost::mem_fn(&X::mf4v_1) != boost::mem_fn(&X::mf4v_2) );
BOOST_TEST( boost::mem_fn(&X::cmf4v_1) == boost::mem_fn(&X::cmf4v_1) );
BOOST_TEST( boost::mem_fn(&X::cmf4v_1) != boost::mem_fn(&X::cmf4v_2) );
// 5
BOOST_TEST( boost::mem_fn(&X::mf5_1) == boost::mem_fn(&X::mf5_1) );
BOOST_TEST( boost::mem_fn(&X::mf5_1) != boost::mem_fn(&X::mf5_2) );
BOOST_TEST( boost::mem_fn(&X::cmf5_1) == boost::mem_fn(&X::cmf5_1) );
BOOST_TEST( boost::mem_fn(&X::cmf5_1) != boost::mem_fn(&X::cmf5_2) );
BOOST_TEST( boost::mem_fn(&X::mf5v_1) == boost::mem_fn(&X::mf5v_1) );
BOOST_TEST( boost::mem_fn(&X::mf5v_1) != boost::mem_fn(&X::mf5v_2) );
BOOST_TEST( boost::mem_fn(&X::cmf5v_1) == boost::mem_fn(&X::cmf5v_1) );
BOOST_TEST( boost::mem_fn(&X::cmf5v_1) != boost::mem_fn(&X::cmf5v_2) );
// 6
BOOST_TEST( boost::mem_fn(&X::mf6_1) == boost::mem_fn(&X::mf6_1) );
BOOST_TEST( boost::mem_fn(&X::mf6_1) != boost::mem_fn(&X::mf6_2) );
BOOST_TEST( boost::mem_fn(&X::cmf6_1) == boost::mem_fn(&X::cmf6_1) );
BOOST_TEST( boost::mem_fn(&X::cmf6_1) != boost::mem_fn(&X::cmf6_2) );
BOOST_TEST( boost::mem_fn(&X::mf6v_1) == boost::mem_fn(&X::mf6v_1) );
BOOST_TEST( boost::mem_fn(&X::mf6v_1) != boost::mem_fn(&X::mf6v_2) );
BOOST_TEST( boost::mem_fn(&X::cmf6v_1) == boost::mem_fn(&X::cmf6v_1) );
BOOST_TEST( boost::mem_fn(&X::cmf6v_1) != boost::mem_fn(&X::cmf6v_2) );
// 7
BOOST_TEST( boost::mem_fn(&X::mf7_1) == boost::mem_fn(&X::mf7_1) );
BOOST_TEST( boost::mem_fn(&X::mf7_1) != boost::mem_fn(&X::mf7_2) );
BOOST_TEST( boost::mem_fn(&X::cmf7_1) == boost::mem_fn(&X::cmf7_1) );
BOOST_TEST( boost::mem_fn(&X::cmf7_1) != boost::mem_fn(&X::cmf7_2) );
BOOST_TEST( boost::mem_fn(&X::mf7v_1) == boost::mem_fn(&X::mf7v_1) );
BOOST_TEST( boost::mem_fn(&X::mf7v_1) != boost::mem_fn(&X::mf7v_2) );
BOOST_TEST( boost::mem_fn(&X::cmf7v_1) == boost::mem_fn(&X::cmf7v_1) );
BOOST_TEST( boost::mem_fn(&X::cmf7v_1) != boost::mem_fn(&X::cmf7v_2) );
// 8
BOOST_TEST( boost::mem_fn(&X::mf8_1) == boost::mem_fn(&X::mf8_1) );
BOOST_TEST( boost::mem_fn(&X::mf8_1) != boost::mem_fn(&X::mf8_2) );
BOOST_TEST( boost::mem_fn(&X::cmf8_1) == boost::mem_fn(&X::cmf8_1) );
BOOST_TEST( boost::mem_fn(&X::cmf8_1) != boost::mem_fn(&X::cmf8_2) );
BOOST_TEST( boost::mem_fn(&X::mf8v_1) == boost::mem_fn(&X::mf8v_1) );
BOOST_TEST( boost::mem_fn(&X::mf8v_1) != boost::mem_fn(&X::mf8v_2) );
BOOST_TEST( boost::mem_fn(&X::cmf8v_1) == boost::mem_fn(&X::cmf8v_1) );
BOOST_TEST( boost::mem_fn(&X::cmf8v_1) != boost::mem_fn(&X::cmf8v_2) );
return boost::report_errors();
}

View File

@@ -0,0 +1,186 @@
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif
//
// mem_fn_fastcall_test.cpp - a test for mem_fn.hpp + __fastcall
//
// Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#define BOOST_MEM_FN_ENABLE_FASTCALL
#include <boost/mem_fn.hpp>
#include <boost/shared_ptr.hpp>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(push, 3)
#endif
#include <iostream>
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
#pragma warning(pop)
#endif
struct X
{
mutable unsigned int hash;
X(): hash(0) {}
void __fastcall f0() { f1(17); }
void __fastcall g0() const { g1(17); }
void __fastcall f1(int a1) { hash = (hash * 17041 + a1) % 32768; }
void __fastcall g1(int a1) const { hash = (hash * 17041 + a1 * 2) % 32768; }
void __fastcall f2(int a1, int a2) { f1(a1); f1(a2); }
void __fastcall g2(int a1, int a2) const { g1(a1); g1(a2); }
void __fastcall f3(int a1, int a2, int a3) { f2(a1, a2); f1(a3); }
void __fastcall g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); }
void __fastcall f4(int a1, int a2, int a3, int a4) { f3(a1, a2, a3); f1(a4); }
void __fastcall g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); }
void __fastcall f5(int a1, int a2, int a3, int a4, int a5) { f4(a1, a2, a3, a4); f1(a5); }
void __fastcall g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); }
void __fastcall f6(int a1, int a2, int a3, int a4, int a5, int a6) { f5(a1, a2, a3, a4, a5); f1(a6); }
void __fastcall g6(int a1, int a2, int a3, int a4, int a5, int a6) const { g5(a1, a2, a3, a4, a5); g1(a6); }
void __fastcall f7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) { f6(a1, a2, a3, a4, a5, a6); f1(a7); }
void __fastcall g7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) const { g6(a1, a2, a3, a4, a5, a6); g1(a7); }
void __fastcall f8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) { f7(a1, a2, a3, a4, a5, a6, a7); f1(a8); }
void __fastcall g8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) const { g7(a1, a2, a3, a4, a5, a6, a7); g1(a8); }
};
int detect_errors(bool x)
{
if(x)
{
std::cerr << "no errors detected.\n";
return 0;
}
else
{
std::cerr << "test failed.\n";
return 1;
}
}
int main()
{
using boost::mem_fn;
X x;
X const & rcx = x;
X const * pcx = &x;
boost::shared_ptr<X> sp(new X);
mem_fn(&X::f0)(x);
mem_fn(&X::f0)(&x);
mem_fn(&X::f0)(sp);
mem_fn(&X::g0)(x);
mem_fn(&X::g0)(rcx);
mem_fn(&X::g0)(&x);
mem_fn(&X::g0)(pcx);
mem_fn(&X::g0)(sp);
mem_fn(&X::f1)(x, 1);
mem_fn(&X::f1)(&x, 1);
mem_fn(&X::f1)(sp, 1);
mem_fn(&X::g1)(x, 1);
mem_fn(&X::g1)(rcx, 1);
mem_fn(&X::g1)(&x, 1);
mem_fn(&X::g1)(pcx, 1);
mem_fn(&X::g1)(sp, 1);
mem_fn(&X::f2)(x, 1, 2);
mem_fn(&X::f2)(&x, 1, 2);
mem_fn(&X::f2)(sp, 1, 2);
mem_fn(&X::g2)(x, 1, 2);
mem_fn(&X::g2)(rcx, 1, 2);
mem_fn(&X::g2)(&x, 1, 2);
mem_fn(&X::g2)(pcx, 1, 2);
mem_fn(&X::g2)(sp, 1, 2);
mem_fn(&X::f3)(x, 1, 2, 3);
mem_fn(&X::f3)(&x, 1, 2, 3);
mem_fn(&X::f3)(sp, 1, 2, 3);
mem_fn(&X::g3)(x, 1, 2, 3);
mem_fn(&X::g3)(rcx, 1, 2, 3);
mem_fn(&X::g3)(&x, 1, 2, 3);
mem_fn(&X::g3)(pcx, 1, 2, 3);
mem_fn(&X::g3)(sp, 1, 2, 3);
mem_fn(&X::f4)(x, 1, 2, 3, 4);
mem_fn(&X::f4)(&x, 1, 2, 3, 4);
mem_fn(&X::f4)(sp, 1, 2, 3, 4);
mem_fn(&X::g4)(x, 1, 2, 3, 4);
mem_fn(&X::g4)(rcx, 1, 2, 3, 4);
mem_fn(&X::g4)(&x, 1, 2, 3, 4);
mem_fn(&X::g4)(pcx, 1, 2, 3, 4);
mem_fn(&X::g4)(sp, 1, 2, 3, 4);
mem_fn(&X::f5)(x, 1, 2, 3, 4, 5);
mem_fn(&X::f5)(&x, 1, 2, 3, 4, 5);
mem_fn(&X::f5)(sp, 1, 2, 3, 4, 5);
mem_fn(&X::g5)(x, 1, 2, 3, 4, 5);
mem_fn(&X::g5)(rcx, 1, 2, 3, 4, 5);
mem_fn(&X::g5)(&x, 1, 2, 3, 4, 5);
mem_fn(&X::g5)(pcx, 1, 2, 3, 4, 5);
mem_fn(&X::g5)(sp, 1, 2, 3, 4, 5);
mem_fn(&X::f6)(x, 1, 2, 3, 4, 5, 6);
mem_fn(&X::f6)(&x, 1, 2, 3, 4, 5, 6);
mem_fn(&X::f6)(sp, 1, 2, 3, 4, 5, 6);
mem_fn(&X::g6)(x, 1, 2, 3, 4, 5, 6);
mem_fn(&X::g6)(rcx, 1, 2, 3, 4, 5, 6);
mem_fn(&X::g6)(&x, 1, 2, 3, 4, 5, 6);
mem_fn(&X::g6)(pcx, 1, 2, 3, 4, 5, 6);
mem_fn(&X::g6)(sp, 1, 2, 3, 4, 5, 6);
mem_fn(&X::f7)(x, 1, 2, 3, 4, 5, 6, 7);
mem_fn(&X::f7)(&x, 1, 2, 3, 4, 5, 6, 7);
mem_fn(&X::f7)(sp, 1, 2, 3, 4, 5, 6, 7);
mem_fn(&X::g7)(x, 1, 2, 3, 4, 5, 6, 7);
mem_fn(&X::g7)(rcx, 1, 2, 3, 4, 5, 6, 7);
mem_fn(&X::g7)(&x, 1, 2, 3, 4, 5, 6, 7);
mem_fn(&X::g7)(pcx, 1, 2, 3, 4, 5, 6, 7);
mem_fn(&X::g7)(sp, 1, 2, 3, 4, 5, 6, 7);
mem_fn(&X::f8)(x, 1, 2, 3, 4, 5, 6, 7, 8);
mem_fn(&X::f8)(&x, 1, 2, 3, 4, 5, 6, 7, 8);
mem_fn(&X::f8)(sp, 1, 2, 3, 4, 5, 6, 7, 8);
mem_fn(&X::g8)(x, 1, 2, 3, 4, 5, 6, 7, 8);
mem_fn(&X::g8)(rcx, 1, 2, 3, 4, 5, 6, 7, 8);
mem_fn(&X::g8)(&x, 1, 2, 3, 4, 5, 6, 7, 8);
mem_fn(&X::g8)(pcx, 1, 2, 3, 4, 5, 6, 7, 8);
mem_fn(&X::g8)(sp, 1, 2, 3, 4, 5, 6, 7, 8);
return detect_errors(x.hash == 17610 && sp->hash == 2155);
}

View File

@@ -1,4 +1,6 @@
#if defined(_MSC_VER) && !defined(__ICL)
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
@@ -10,10 +12,9 @@
//
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#define BOOST_MEM_FN_ENABLE_STDCALL

View File

@@ -1,4 +1,6 @@
#if defined(_MSC_VER) && !defined(__ICL)
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
@@ -8,12 +10,11 @@
//
// mem_fn_test.cpp - a test for mem_fn.hpp
//
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
// Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/mem_fn.hpp>
@@ -179,5 +180,5 @@ int main()
mem_fn(&X::g8)(pcx, 1, 2, 3, 4, 5, 6, 7, 8);
mem_fn(&X::g8)(sp, 1, 2, 3, 4, 5, 6, 7, 8);
return detect_errors(x.hash == 17610 && sp->hash == 2155);
return detect_errors(mem_fn(&X::hash)(x) == 17610 && mem_fn(&X::hash)(sp) == 2155);
}

View File

@@ -1,4 +1,6 @@
#if defined(_MSC_VER) && !defined(__ICL)
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
@@ -10,10 +12,9 @@
//
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/mem_fn.hpp>