mirror of
https://github.com/boostorg/bind.git
synced 2026-04-13 13:15:50 +02:00
Compare commits
14 Commits
boost-1.29
...
boost-1.30
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
85115dffd8 | ||
|
|
757d0122de | ||
|
|
3a80081642 | ||
|
|
b32ebea99c | ||
|
|
5454a5aac6 | ||
|
|
c9db3c51ea | ||
|
|
8c09072ead | ||
|
|
4876b82a73 | ||
|
|
7b7784d470 | ||
|
|
eca328b27c | ||
|
|
ad46d513d7 | ||
|
|
cc3ebc18b8 | ||
|
|
5a10daef4d | ||
|
|
51e4031aaf |
@@ -22,6 +22,7 @@
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
#include <boost/mem_fn.hpp>
|
||||
#include <boost/type.hpp>
|
||||
#include <boost/bind/arg.hpp>
|
||||
|
||||
// Borland-specific bug, visit_each() silently fails to produce code
|
||||
@@ -1133,6 +1134,18 @@ template<class A1, class A2, class A3, class A4, class A5, class A6, class A7, c
|
||||
typedef list9<B1, B2, B3, B4, B5, B6, B7, B8, B9> type;
|
||||
};
|
||||
|
||||
// g++ 2.95 specific helper; used by the data member overload
|
||||
|
||||
template<class T> struct add_cref
|
||||
{
|
||||
typedef T const & type;
|
||||
};
|
||||
|
||||
template<> struct add_cref<void>
|
||||
{
|
||||
typedef void type;
|
||||
};
|
||||
|
||||
} // namespace _bi
|
||||
|
||||
// visit_each
|
||||
@@ -1235,6 +1248,88 @@ template<class R, class F, class A1, class A2, class A3, class A4, class A5, cla
|
||||
return _bi::bind_t<R, F, list_type>(f, list_type(a1, a2, a3, a4, a5, a6, a7, a8, a9));
|
||||
}
|
||||
|
||||
// generic function objects, alternative syntax
|
||||
|
||||
template<class R, class F>
|
||||
_bi::bind_t<R, F, _bi::list0>
|
||||
BOOST_BIND(boost::type<R>, F f)
|
||||
{
|
||||
typedef _bi::list0 list_type;
|
||||
return _bi::bind_t<R, F, list_type> (f, list_type());
|
||||
}
|
||||
|
||||
template<class R, class F, class A1>
|
||||
_bi::bind_t<R, F, typename _bi::list_av_1<A1>::type>
|
||||
BOOST_BIND(boost::type<R>, F f, A1 a1)
|
||||
{
|
||||
typedef typename _bi::list_av_1<A1>::type list_type;
|
||||
return _bi::bind_t<R, F, list_type> (f, list_type(a1));
|
||||
}
|
||||
|
||||
template<class R, class F, class A1, class A2>
|
||||
_bi::bind_t<R, F, typename _bi::list_av_2<A1, A2>::type>
|
||||
BOOST_BIND(boost::type<R>, F f, A1 a1, A2 a2)
|
||||
{
|
||||
typedef typename _bi::list_av_2<A1, A2>::type list_type;
|
||||
return _bi::bind_t<R, F, list_type> (f, list_type(a1, a2));
|
||||
}
|
||||
|
||||
template<class R, class F, class A1, class A2, class A3>
|
||||
_bi::bind_t<R, F, typename _bi::list_av_3<A1, A2, A3>::type>
|
||||
BOOST_BIND(boost::type<R>, F f, A1 a1, A2 a2, A3 a3)
|
||||
{
|
||||
typedef typename _bi::list_av_3<A1, A2, A3>::type list_type;
|
||||
return _bi::bind_t<R, F, list_type>(f, list_type(a1, a2, a3));
|
||||
}
|
||||
|
||||
template<class R, class F, class A1, class A2, class A3, class A4>
|
||||
_bi::bind_t<R, F, typename _bi::list_av_4<A1, A2, A3, A4>::type>
|
||||
BOOST_BIND(boost::type<R>, F f, A1 a1, A2 a2, A3 a3, A4 a4)
|
||||
{
|
||||
typedef typename _bi::list_av_4<A1, A2, A3, A4>::type list_type;
|
||||
return _bi::bind_t<R, F, list_type>(f, list_type(a1, a2, a3, a4));
|
||||
}
|
||||
|
||||
template<class R, class F, class A1, class A2, class A3, class A4, class A5>
|
||||
_bi::bind_t<R, F, typename _bi::list_av_5<A1, A2, A3, A4, A5>::type>
|
||||
BOOST_BIND(boost::type<R>, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
|
||||
{
|
||||
typedef typename _bi::list_av_5<A1, A2, A3, A4, A5>::type list_type;
|
||||
return _bi::bind_t<R, F, list_type>(f, list_type(a1, a2, a3, a4, a5));
|
||||
}
|
||||
|
||||
template<class R, class F, class A1, class A2, class A3, class A4, class A5, class A6>
|
||||
_bi::bind_t<R, F, typename _bi::list_av_6<A1, A2, A3, A4, A5, A6>::type>
|
||||
BOOST_BIND(boost::type<R>, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6)
|
||||
{
|
||||
typedef typename _bi::list_av_6<A1, A2, A3, A4, A5, A6>::type list_type;
|
||||
return _bi::bind_t<R, F, list_type>(f, list_type(a1, a2, a3, a4, a5, a6));
|
||||
}
|
||||
|
||||
template<class R, class F, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
|
||||
_bi::bind_t<R, F, typename _bi::list_av_7<A1, A2, A3, A4, A5, A6, A7>::type>
|
||||
BOOST_BIND(boost::type<R>, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7)
|
||||
{
|
||||
typedef typename _bi::list_av_7<A1, A2, A3, A4, A5, A6, A7>::type list_type;
|
||||
return _bi::bind_t<R, F, list_type>(f, list_type(a1, a2, a3, a4, a5, a6, a7));
|
||||
}
|
||||
|
||||
template<class R, class F, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
|
||||
_bi::bind_t<R, F, typename _bi::list_av_8<A1, A2, A3, A4, A5, A6, A7, A8>::type>
|
||||
BOOST_BIND(boost::type<R>, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8)
|
||||
{
|
||||
typedef typename _bi::list_av_8<A1, A2, A3, A4, A5, A6, A7, A8>::type list_type;
|
||||
return _bi::bind_t<R, F, list_type>(f, list_type(a1, a2, a3, a4, a5, a6, a7, a8));
|
||||
}
|
||||
|
||||
template<class R, class F, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
|
||||
_bi::bind_t<R, F, typename _bi::list_av_9<A1, A2, A3, A4, A5, A6, A7, A8, A9>::type>
|
||||
BOOST_BIND(boost::type<R>, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9)
|
||||
{
|
||||
typedef typename _bi::list_av_9<A1, A2, A3, A4, A5, A6, A7, A8, A9>::type list_type;
|
||||
return _bi::bind_t<R, F, list_type>(f, list_type(a1, a2, a3, a4, a5, a6, a7, a8, a9));
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
|
||||
|
||||
// adaptable function objects
|
||||
@@ -1403,8 +1498,21 @@ template<class F, class A1, class A2, class A3, class A4, class A5, class A6, cl
|
||||
|
||||
// data member pointers
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ == 2)
|
||||
|
||||
template<class R, class T, class A1>
|
||||
_bi::bind_t< R const &, _mfi::dm<R, T>, typename _bi::list_av_1<A1>::type >
|
||||
_bi::bind_t< typename _bi::add_cref<R>::type, _mfi::dm<R, T>, typename _bi::list_av_1<A1>::type >
|
||||
BOOST_BIND(R T::*f, A1 a1)
|
||||
{
|
||||
typedef _mfi::dm<R, T> F;
|
||||
typedef typename _bi::list_av_1<A1>::type list_type;
|
||||
return _bi::bind_t<typename _bi::add_cref<R>::type, F, list_type>(F(f), list_type(a1));
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
template<class R, class T, class A1>
|
||||
_bi::bind_t< R const &, _mfi::dm<R, T>, typename _bi::list_av_1<A1>::type >
|
||||
BOOST_BIND(R T::*f, A1 a1)
|
||||
{
|
||||
typedef _mfi::dm<R, T> F;
|
||||
@@ -1412,6 +1520,8 @@ template<class R, class T, class A1>
|
||||
return _bi::bind_t<R const &, F, list_type>(F(f), list_type(a1));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#ifndef BOOST_BIND_NO_PLACEHOLDERS
|
||||
|
||||
@@ -36,7 +36,7 @@ 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) && BOOST_MSVC <= 1300
|
||||
#elif (defined(BOOST_MSVC) && BOOST_MSVC <= 1300) || (defined(__DECCXX_VER) && __DECCXX_VER <= 60590031) || defined(__MWERKS__)
|
||||
|
||||
static boost::arg<1> _1;
|
||||
static boost::arg<2> _2;
|
||||
|
||||
@@ -20,19 +20,11 @@
|
||||
//
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/get_pointer.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
|
||||
|
||||
200
ref.html
200
ref.html
@@ -1,195 +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>
|
||||
</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> 1.00.0004 (2002-01-27)</small></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" height="64"> </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<T></b>, the two functions <b>boost::ref</b>
|
||||
and <b>boost::cref</b> that return instances of <b>boost::reference_wrapper<T></b>,
|
||||
and the two traits classes <b>boost::is_reference_wrapper<T></b> and <b>boost::unwrap_reference<T></b>.
|
||||
</p>
|
||||
<p>
|
||||
The purpose of <b>boost::reference_wrapper<T></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<T></b> provides an
|
||||
implicit conversion to <b>T &</b>. This usually allows the function
|
||||
templates to work on references unmodified.
|
||||
</p>
|
||||
<p>
|
||||
<b>boost::reference_wrapper<T></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<X>(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<X const>(x)</b>.
|
||||
</p>
|
||||
<p>
|
||||
The expression <b>boost::is_reference_wrapper<T>::value</b> is <b>true</b>
|
||||
if <b>T</b> is a <b>reference_wrapper</b>, and <b>false</b>
|
||||
otherwise.
|
||||
</p>
|
||||
<p>
|
||||
The type-expression <b>boost::unwrap_reference<T>::type</b> is <b>T::type</b>
|
||||
if <b>T</b> is a <b>reference_wrapper</b>, <b>T</b> otherwise.
|
||||
</p>
|
||||
<h2>Interface</h2>
|
||||
<h3>Synopsis</h3>
|
||||
<pre>
|
||||
namespace boost
|
||||
{
|
||||
template<class T> class <a href="#reference_wrapper">reference_wrapper</a>;
|
||||
template<class T> reference_wrapper<T> <a href="#ref">ref</a>(T & t);
|
||||
template<class T> reference_wrapper<T const> <a href="#cref">cref</a>(T const & t);
|
||||
template<class T> class is_reference_wrapper<T const>;
|
||||
template<class T> class unwrap_reference<T const>;
|
||||
}
|
||||
</pre>
|
||||
<h3><a name="reference_wrapper">reference_wrapper</a></h3>
|
||||
<pre>
|
||||
template<class T> class reference_wrapper
|
||||
{
|
||||
public:
|
||||
typedef T type;
|
||||
|
||||
explicit <a href="#rt_construct">reference_wrapper</a>(T & t);
|
||||
|
||||
<a href="#rt_operator">operator T &</a> () const;
|
||||
|
||||
T & <a href="#rt_get">get</a>() const;
|
||||
T* <a href="#rt_get_pointer">get_pointer</a>() const;
|
||||
};
|
||||
</pre>
|
||||
<h4><a name="rt_construct">explicit reference_wrapper(T & 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 & () 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 & get() const</a></h4>
|
||||
<blockquote>
|
||||
<p>
|
||||
<b>Returns:</b> the stored reference.
|
||||
</p>
|
||||
<p>
|
||||
<b>Throws:</b> Nothing.
|
||||
</p>
|
||||
</blockquote>
|
||||
<h4><a name="rt_get_pointer">T* get_pointer() const</a></h4>
|
||||
<blockquote>
|
||||
<p>
|
||||
<b>Returns:</b> a pointer to the stored object.
|
||||
</p>
|
||||
<p>
|
||||
<b>Throws:</b> Nothing.
|
||||
</p>
|
||||
</blockquote>
|
||||
<h3><a name="ref">ref</a></h3>
|
||||
<pre>
|
||||
template<class T> reference_wrapper<T> ref(T & t);
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
<b>Returns:</b> <tt>reference_wrapper<T>(t)</tt>.
|
||||
</p>
|
||||
<p>
|
||||
<b>Throws:</b> Nothing.
|
||||
</p>
|
||||
</blockquote>
|
||||
<h3><a name="cref">cref</a></h3>
|
||||
<pre>
|
||||
template<class T> reference_wrapper<T const> cref(T const & t);
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
<b>Returns:</b> <tt>reference_wrapper<T const>(t)</tt>.
|
||||
</p>
|
||||
<p>
|
||||
<b>Throws:</b> Nothing.
|
||||
</p>
|
||||
</blockquote>
|
||||
<h3><a name="is_reference_wrapper">is_reference_wrapper</a></h3>
|
||||
<pre>
|
||||
template<class T> class is_reference_wrapper<T const>
|
||||
{
|
||||
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<class T> class unwrap_reference<T const>
|
||||
{
|
||||
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ä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 © 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 "as
|
||||
is" without express or implied warranty, and with no claim as to its
|
||||
suitability for any purpose.</small></p>
|
||||
</body>
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0; URL=../../doc/html/ref.html">
|
||||
</head>
|
||||
<body>
|
||||
Automatic redirection failed, please go to
|
||||
<a href="../../doc/html/ref.html">../../doc/html/ref.html</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
26
test/Jamfile
Normal file
26
test/Jamfile
Normal file
@@ -0,0 +1,26 @@
|
||||
# Boost.Bind Library test Jamfile
|
||||
#
|
||||
# Copyright (c) 2003 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
|
||||
SEARCH on testing.jam = $(BOOST_BUILD_PATH) ;
|
||||
include testing.jam ;
|
||||
|
||||
# Make tests run by default.
|
||||
DEPENDS all : bind ;
|
||||
|
||||
{
|
||||
test-suite "bind"
|
||||
: [ run bind_test.cpp ]
|
||||
[ run mem_fn_test.cpp ]
|
||||
[ run mem_fn_void_test.cpp ]
|
||||
[ run mem_fn_derived_test.cpp ]
|
||||
;
|
||||
}
|
||||
@@ -190,12 +190,31 @@ void function_object_test()
|
||||
|
||||
#if !defined(__MWERKS__) || (__MWERKS__ > 0x2406) // 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)
|
||||
@@ -487,6 +506,7 @@ 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();
|
||||
Reference in New Issue
Block a user