diff options
author | Michael Elkstrand <michael@elehack.net> | 2007-07-28 12:19:01 +0000 |
---|---|---|
committer | Murray Cumming <murrayc@src.gnome.org> | 2007-07-28 12:19:01 +0000 |
commit | 5f22a6a28079867680033f8dd9b6433e93f74d56 (patch) | |
tree | 3653cb895ade9157bf1653726fc18cb55e3a7f1f | |
parent | 552bd485674ebffcdd0bf9a9970d98b02e0ceeb6 (diff) | |
download | sigc++-5f22a6a28079867680033f8dd9b6433e93f74d56.tar.gz |
slot_iterator_buf, slot_reverse_iterator_buf: Added typedefs for
2007-07-28 Michael Elkstrand <michael@elehack.net>
* sigc++/macros/signal.h.m4: slot_iterator_buf,
slot_reverse_iterator_buf: Added typedefs for
value_type, reference, and pointer, so that these
iterators are more like standard C++ iterators, so they can
be used with standard C++ algorithms.
* tests/Makefile.am:
* tests/test_accum_iter.cc: Added a test for this.
Bug #417926.
svn path=/trunk/; revision=284
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | sigc++/macros/signal.h.m4 | 12 | ||||
-rw-r--r-- | tests/Makefile.am | 4 | ||||
-rw-r--r-- | tests/test_accum_iter.cc | 43 |
4 files changed, 69 insertions, 1 deletions
@@ -1,3 +1,14 @@ +2007-07-28 Michael Elkstrand <michael@elehack.net> + + * sigc++/macros/signal.h.m4: slot_iterator_buf, + slot_reverse_iterator_buf: Added typedefs for + value_type, reference, and pointer, so that these + iterators are more like standard C++ iterators, so they can + be used with standard C++ algorithms. + * tests/Makefile.am: + * tests/test_accum_iter.cc: Added a test for this. + Bug #417926. + 2006-11-14 Daniel Elstner <daniel.kitta@gmail.com> * autogen.sh: Wholly replace this script with a critter from one diff --git a/sigc++/macros/signal.h.m4 b/sigc++/macros/signal.h.m4 index 57bcfc6..beb54e6 100644 --- a/sigc++/macros/signal.h.m4 +++ b/sigc++/macros/signal.h.m4 @@ -834,6 +834,12 @@ struct slot_iterator_buf typedef ptrdiff_t difference_type; typedef std::bidirectional_iterator_tag iterator_category; + //These are needed just to make this a proper C++ iterator, + //that can be used with standard C++ algorithms. + typedef T_result value_type; + typedef T_result& reference; + typedef T_result* pointer; + typedef T_emitter emitter_type; typedef T_result result_type; typedef typename T_emitter::slot_type slot_type; @@ -982,6 +988,12 @@ struct slot_reverse_iterator_buf typedef ptrdiff_t difference_type; typedef std::bidirectional_iterator_tag iterator_category; + //These are needed just to make this a proper C++ iterator, + //that can be used with standard C++ algorithms. + typedef T_result value_type; + typedef T_result& reference; + typedef T_result* pointer; + typedef T_emitter emitter_type; typedef T_result result_type; typedef typename T_emitter::slot_type slot_type; diff --git a/tests/Makefile.am b/tests/Makefile.am index 4f69805..29e7ebb 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -29,7 +29,8 @@ noinst_PROGRAMS= \ test_limit_reference \ test_copy_invalid_slot \ test_slot_disconnect \ - test_custom + test_custom \ + test_accum_iter #Disabled: # test_lambda - The Tru64 compiler can't build this when not using -std strict_ansi -model ansi, so let's not worry about it. @@ -68,3 +69,4 @@ test_limit_reference_SOURCES = test_limit_reference.cc test_copy_invalid_slot_SOURCES = test_copy_invalid_slot.cc test_slot_disconnect_SOURCES = test_slot_disconnect.cc test_custom_SOURCES = test_custom.cc +test_accum_iter_SOURCES = test_accum_iter.cc diff --git a/tests/test_accum_iter.cc b/tests/test_accum_iter.cc new file mode 100644 index 0000000..462c2ec --- /dev/null +++ b/tests/test_accum_iter.cc @@ -0,0 +1,43 @@ +#include <sigc++/sigc++.h> +#include <iostream> +#include <algorithm> +#include <functional> + +#include <new> +SIGC_USING_STD(new) + +static int ident(int i) +{ + return i; +} + +template<typename T> +struct min_accum +{ + typedef T result_type; + + template<class I> + typename std::iterator_traits<I>::value_type operator()(I i1, I i2) + { + return *std::min_element(i1, i2); + } +}; + +int main() +{ + sigc::signal0<int,min_accum<int> > signal; + + signal.connect( + sigc::bind(sigc::ptr_fun(ident), 3)); + signal.connect( + sigc::bind(sigc::ptr_fun(ident), 1)); + signal.connect( + sigc::bind(sigc::ptr_fun(ident), 42)); + + int rv = signal(); + std::cout <<rv <<std::endl; + if (rv != 1) + return 1; + else + return 0; +} |