diff options
author | hillj <hillj@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2008-01-14 16:17:45 +0000 |
---|---|---|
committer | hillj <hillj@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2008-01-14 16:17:45 +0000 |
commit | afe52fcb8e689e59dcc1df72c0b8d113ebe2a898 (patch) | |
tree | dc3356acce3dc9b0274eccc7c9cd09ae27ce8400 /ACE/tests/STL_algorithm_Test_T.cpp | |
parent | 05e9e499401f871ddd8a27021b3b49b91aac0e32 (diff) | |
download | ATCD-afe52fcb8e689e59dcc1df72c0b8d113ebe2a898.tar.gz |
Mon Jan 14 16:14:11 UTC 2008 James H. Hill <hillj@isis.vanderbilt.edu>
Diffstat (limited to 'ACE/tests/STL_algorithm_Test_T.cpp')
-rw-r--r-- | ACE/tests/STL_algorithm_Test_T.cpp | 72 |
1 files changed, 55 insertions, 17 deletions
diff --git a/ACE/tests/STL_algorithm_Test_T.cpp b/ACE/tests/STL_algorithm_Test_T.cpp index 6972fd20df2..cb9f63d71b5 100644 --- a/ACE/tests/STL_algorithm_Test_T.cpp +++ b/ACE/tests/STL_algorithm_Test_T.cpp @@ -7,34 +7,72 @@ #include <algorithm> #include <typeinfo> -template <typename ITEM> -static void -for_each_callback (ITEM & item) +template <typename T> +class Element_Counter { - // do nothing; just testing compilation and execution - ACE_DEBUG ((LM_DEBUG, - "algorithm test: for_each_callback\n")); +public: + Element_Counter (void) + : count_ (0) + { - ACE_UNUSED_ARG (item); -} + } + + void operator () (typename T::value_type & item) + { + ++ this->count_; + ACE_UNUSED_ARG (item); + } + + const Element_Counter & operator = (const Element_Counter & ec) + { + this->count_ = ec.count_; + return *this; + } + + typename T::difference_type get_count (void) const + { + return this->count_; + } + +private: + // Number of elements iterated over. + typename T::difference_type count_; +}; template <typename T> int test_STL_algorithm (T & container) { - // We are only validating that the container's iterators compile with - // the <algorithm> header. + // We are only validating that the container's iterators + // compile with the <algorithm> header. ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("running STL algorithm test for `%s'\n"), typeid (T).name ())); - // Test the (reverse) iterator using std::for_each. - std::for_each (container.begin (), - container.end (), - &for_each_callback <typename T::value_type>); + // Test the forward iterator using std::for_each. + ACE_DEBUG ((LM_DEBUG, + "testing forward iterator\n")); - std::for_each (container.rbegin (), - container.rend (), - &for_each_callback <typename T::value_type>); + typename T::difference_type count = + std::for_each (container.begin (), + container.end (), + Element_Counter <T> ()).get_count (); + + ACE_DEBUG ((LM_DEBUG, + "std::for_each handled %d elements\n", + count)); + + // Test the reverse iterator using std::for_each. + ACE_DEBUG ((LM_DEBUG, + "testing reverse iterator\n")); + + count = + std::for_each (container.rbegin (), + container.rend (), + Element_Counter <T> ()).get_count (); + + ACE_DEBUG ((LM_DEBUG, + "std::for_each handled %d elements\n", + count)); return 0; } |