diff options
| author | Martin Schulze <teebaum@cvs.gnome.org> | 2003-11-10 22:49:20 +0000 |
|---|---|---|
| committer | Martin Schulze <teebaum@src.gnome.org> | 2003-11-10 22:49:20 +0000 |
| commit | 89a6d6581ee813108a0340810efbe78a6c966a6e (patch) | |
| tree | 5158bf7f38c24f6c2e5a1eacdc80c0180de9f8ac | |
| parent | 113387c2bf10b0ac390e311e422b774c3d683bf1 (diff) | |
| download | sigc++-89a6d6581ee813108a0340810efbe78a6c966a6e.tar.gz | |
Add unnumbered bind() and hide() overloads to make specifying the argument
2003-11-10 Martin Schulze <teebaum@cvs.gnome.org>
* sigc++/adaptors/macros/[bind,hide].h.m4: Add unnumbered
bind() and hide() overloads to make specifying the argument
position optional (Proposed by Jeff Franks).
* tests/test_[bind,hide].cc: Test unnumbered bind() and hide().
* sigc++/adaptors/macros/adaptor_trait.h.m4:
Change "#ifdef MSVC" to "#ifdef _MSC_VER" (Roel Vanhout).
| -rw-r--r-- | ChangeLog | 9 | ||||
| -rw-r--r-- | sigc++/adaptors/macros/adaptor_trait.h.m4 | 2 | ||||
| -rw-r--r-- | sigc++/adaptors/macros/bind.h.m4 | 72 | ||||
| -rw-r--r-- | sigc++/adaptors/macros/hide.h.m4 | 8 | ||||
| -rw-r--r-- | sigc++/functors/macros/functor_trait.h.m4 | 3 | ||||
| -rw-r--r-- | tests/test_bind.cc | 2 | ||||
| -rw-r--r-- | tests/test_hide.cc | 1 |
7 files changed, 90 insertions, 7 deletions
@@ -1,3 +1,12 @@ +2003-11-10 Martin Schulze <teebaum@cvs.gnome.org> + + * sigc++/adaptors/macros/[bind,hide].h.m4: Add unnumbered + bind() and hide() overloads to make specifying the argument + position optional (Proposed by Jeff Franks). + * tests/test_[bind,hide].cc: Test unnumbered bind() and hide(). + * sigc++/adaptors/macros/adaptor_trait.h.m4: + Change "#ifdef MSVC" to "#ifdef _MSC_VER" (Roel Vanhout). + 2003-11-09 Martin Schulze <teebaum@cvs.gnome.org> * sigc++/functors/macros/slot.h.m4: Change functor type in diff --git a/sigc++/adaptors/macros/adaptor_trait.h.m4 b/sigc++/adaptors/macros/adaptor_trait.h.m4 index f73af86..b715ea4 100644 --- a/sigc++/adaptors/macros/adaptor_trait.h.m4 +++ b/sigc++/adaptors/macros/adaptor_trait.h.m4 @@ -71,7 +71,7 @@ __FIREWALL__ namespace sigc { -#ifdef MSVC +#ifdef _MSC_VER #define LIBSIGC_TEMPLATE_PREFIX #else #define LIBSIGC_TEMPLATE_PREFIX template diff --git a/sigc++/adaptors/macros/bind.h.m4 b/sigc++/adaptors/macros/bind.h.m4 index 5907387..1f4a3d0 100644 --- a/sigc++/adaptors/macros/bind.h.m4 +++ b/sigc++/adaptors/macros/bind.h.m4 @@ -118,9 +118,9 @@ namespace sigc { /** @defgroup bind bind() * sigc::bind() alters an arbitrary functor by fixing arguments to certain values. - * The mandatory first template argument specifies the number of the + * The optional first template argument specifies the number of the * argument where binding starts. Counting starts from @p 1. A value - * of @p 0 means that binding should start from the last argument. + * of @p 0 or a missing value means that binding should start from the last argument. * Up to three arguments can be bound at a time. * The types of the arguments can optionally be specified if not deduced. * @@ -131,8 +131,10 @@ namespace sigc { * sigc::bind<2>(&foo,1)(2,3); //fixes the second argument and calls foo(2,1,3); * sigc::bind<3>(&foo,1)(2,3); //fixes the third argument and calls foo(2,3,1); * sigc::bind<0>(&foo,1)(2,3); //fixes the last (third) argument and calls foo(2,3,1); + * sigc::bind(&foo,1)(2,3); //same as bind<0>(&foo,1)(2,3); * sigc::bind<1>(&foo,1,2)(3); //fixes the first and second argument and calls foo(1,2,3); * sigc::bind<0>(&foo,1,2)(3); //fixes the last two (second and third) arguments and calls foo(3,1,2); + * sigc::bind(&foo,1,2)(3); //same as sigc::bind<0>(&foo,1,2)(3); * @endcode * * The functor sigc::bind() returns can be passed into @@ -142,7 +144,7 @@ namespace sigc { * @code * sigc::signal<void> some_signal; * void foo(int); - * some_signal.connect(sigc::bind<0>(&foo,1)); + * some_signal.connect(sigc::bind(&foo,1)); * @endcode * * You can bind references to functors by passing the objects through @@ -153,7 +155,7 @@ namespace sigc { * int some_int; * sigc::signal<void> some_signal; * void foo(int&); - * some_signal.connect(sigc::bind<0>(&foo,sigc::ref(some_int))); + * some_signal.connect(sigc::bind(&foo,sigc::ref(some_int))); * @endcode * * If you bind an object of a sigc::trackable derived type to a functor @@ -165,7 +167,7 @@ namespace sigc { * struct bar : public sigc::trackable {} some_bar; * sigc::signal<void> some_signal; * void foo(bar&); - * some_signal.connect(sigc::bind<0>(&foo,sigc::ref(some_bar))); + * some_signal.connect(sigc::bind(&foo,sigc::ref(some_bar))); * // disconnected automatically if some_bar goes out of scope * @endcode * @@ -227,6 +229,23 @@ bind(const T_functor& _A_func, T_bound1 _A_b1) (_A_func, _A_b1); } +/** Creates an adaptor of type sigc::bind_functor which fixes the last argument of the passed functor. + * This function overload fixes the last argument of @e _A_func. + * + * @param _A_func Functor that should be wrapped. + * @param _A_b1 Argument to bind to @e _A_func. + * @return Adaptor that executes _A_func with the bound argument on invokation. + * + * @ingroup bind + */ +template <class T_bound1, class T_functor> +inline bind_functor<0, typename unwrap_reference<T_bound1>::type, T_functor> +bind(const T_functor& _A_func, T_bound1 _A_b1) +{ + return bind_functor<0, typename unwrap_reference<T_bound1>::type, T_functor> + (_A_func, _A_b1); +} + /** Creates an adaptor of type sigc::bind_functor which binds the passed arguments to the passed functor. * The template argument @e I_location is mandatory and specifies the * number of the argument where binding should start (counting starts @@ -249,6 +268,26 @@ bind(const T_functor& _A_functor, T_bound1 _A_b1, T_bound2 _A_b2) (bind<I_location?I_location+1:0>(_A_functor, _A_b2), _A_b1); } +/** Creates an adaptor of type sigc::bind_functor which fixes the last two arguments of the passed functor. + * This function overload fixes the last two arguments of @e _A_func. + * + * @param _A_func Functor that should be wrapped. + * @param _A_b1 First argument to bind to @e _A_func. + * @param _A_b2 Second argument to bind to @e _A_func. + * @return Adaptor that executes _A_func with the bound argument on invokation. + * + * @ingroup bind + */ +template <class T_bound1, class T_bound2, class T_functor> +inline bind_functor<0, typename unwrap_reference<T_bound1>::type, + bind_functor<0, typename unwrap_reference<T_bound2>::type, T_functor> > +bind(const T_functor& _A_functor, T_bound1 _A_b1, T_bound2 _A_b2) +{ + return bind_functor<0, typename unwrap_reference<T_bound1>::type, + bind_functor<0, typename unwrap_reference<T_bound2>::type, T_functor> > + (bind(_A_functor, _A_b2), _A_b1); +} + /** Creates an adaptor of type sigc::bind_functor which binds the passed arguments to the passed functor. * The template argument @e I_location is mandatory and specifies the * number of the argument where binding should start (counting starts @@ -274,4 +313,27 @@ bind(const T_functor& _A_functor, T_bound1 _A_b1, T_bound2 _A_b2,T_bound3 _A_b3) (bind<I_location?I_location+1:0>(_A_functor, _A_b2, _A_b3),_A_b1); } +/** Creates an adaptor of type sigc::bind_functor which fixes the last three arguments of the passed functor. + * This function overload fixes the last three arguments of @e _A_func. + * + * @param _A_func Functor that should be wrapped. + * @param _A_b1 First argument to bind to @e _A_func. + * @param _A_b2 Second argument to bind to @e _A_func. + * @param _A_b3 Third argument to bind to @e _A_func. + * @return Adaptor that executes _A_func with the bound argument on invokation. + * + * @ingroup bind + */ +template <class T_bound1, class T_bound2, class T_bound3, class T_functor> +inline bind_functor<0, typename unwrap_reference<T_bound1>::type, + bind_functor<0, typename unwrap_reference<T_bound2>::type, + bind_functor<0, typename unwrap_reference<T_bound3>::type, T_functor> > > +bind(const T_functor& _A_functor, T_bound1 _A_b1, T_bound2 _A_b2,T_bound3 _A_b3) +{ + return bind_functor<0, typename unwrap_reference<T_bound1>::type, + bind_functor<0, typename unwrap_reference<T_bound2>::type, + bind_functor<0, typename unwrap_reference<T_bound3>::type, T_functor> > > + (bind(_A_functor, _A_b2, _A_b3),_A_b1); +} + } /* namespace sigc */ diff --git a/sigc++/adaptors/macros/hide.h.m4 b/sigc++/adaptors/macros/hide.h.m4 index b8f9fe8..b52172f 100644 --- a/sigc++/adaptors/macros/hide.h.m4 +++ b/sigc++/adaptors/macros/hide.h.m4 @@ -114,4 +114,12 @@ hide(const T_functor& _A_func) (_A_func); } +template <class T_functor> +inline hide_functor<0, T_functor> +hide(const T_functor& _A_func) +{ + return hide_functor<0, T_functor> + (_A_func); +} + } /* namespace sigc */ diff --git a/sigc++/functors/macros/functor_trait.h.m4 b/sigc++/functors/macros/functor_trait.h.m4 index eb0ae4f..5285920 100644 --- a/sigc++/functors/macros/functor_trait.h.m4 +++ b/sigc++/functors/macros/functor_trait.h.m4 @@ -81,7 +81,8 @@ namespace sigc { * The nil struct type is used as default template argument in the * unnumbered sigc::signal and sigc::slot templates. * - * @ingroup signal slot + * @ingroup signal + * @ingroup slot */ struct nil; diff --git a/tests/test_bind.cc b/tests/test_bind.cc index 444f39e..483d013 100644 --- a/tests/test_bind.cc +++ b/tests/test_bind.cc @@ -64,9 +64,11 @@ int main() // bind from end sigc::bind<0>(foo(),4)(3); + sigc::bind(foo(),4)(3); // multiple beginning from end sigc::bind<0>(foo(),5,6)(); + sigc::bind(foo(),5,6)(); // used together sigc::bind<1>(sigc::bind<1>(foo(),7),8)(); diff --git a/tests/test_hide.cc b/tests/test_hide.cc index de9dfae..3ef5b9c 100644 --- a/tests/test_hide.cc +++ b/tests/test_hide.cc @@ -31,5 +31,6 @@ int main() std::cout << sigc::hide<1>(foo())(1,2) << std::endl; std::cout << sigc::hide<2>(foo())(1,2) << std::endl; std::cout << sigc::hide<0>(foo())(1) << std::endl; + std::cout << sigc::hide(foo())(1) << std::endl; sigc::hide<0>(foo_void())(1); // void test } |
