ACE+TAO-7_0_8
[ACE_TAO.git] / ACE / tests / STL_algorithm_Test_T.cpp
blob5c9b99cfe6832ea1481324dbf109dc1c6f61743a
1 #ifndef ACE_TESTS_STL_ALGORITHM_TEST_T_CPP
2 #define ACE_TESTS_STL_ALGORITHM_TEST_T_CPP
4 #include "test_config.h"
5 #include <algorithm>
6 #include <typeinfo>
8 template <typename T>
9 class Element_Counter
11 public:
12 Element_Counter (void)
13 : count_ (0)
18 void operator () (typename T::value_type & item)
20 ++ this->count_;
21 ACE_UNUSED_ARG (item);
24 Element_Counter & operator = (const Element_Counter & ec)
26 this->count_ = ec.count_;
27 return *this;
30 typename T::difference_type get_count () const
32 return this->count_;
35 private:
36 // Number of elements iterated over.
37 typename T::difference_type count_;
40 template <typename T>
41 int test_STL_algorithm (T & container)
43 // We are only validating that the container's iterators
44 // compile with the <algorithm> header.
45 ACE_DEBUG ((LM_DEBUG,
46 ACE_TEXT ("running STL algorithm test for `%s'\n"),
47 typeid (T).name ()));
49 // Test the forward iterator using std::for_each.
50 ACE_DEBUG ((LM_DEBUG,
51 "testing forward iterator\n"));
53 typename T::difference_type count =
54 std::for_each (container.begin (),
55 container.end (),
56 Element_Counter <T> ()).get_count ();
58 ACE_DEBUG ((LM_DEBUG,
59 "std::for_each handled %d elements\n",
60 count));
62 // Test the reverse iterator using std::for_each.
63 ACE_DEBUG ((LM_DEBUG,
64 "testing reverse iterator\n"));
66 count =
67 std::for_each (container.rbegin (),
68 container.rend (),
69 Element_Counter <T> ()).get_count ();
71 ACE_DEBUG ((LM_DEBUG,
72 "std::for_each handled %d elements\n",
73 count));
75 return 0;
78 #endif /* ACE_TESTS_STL_ALGORITHM_TEST_T_CPP */