summaryrefslogtreecommitdiff
path: root/tests/STL_algorithm_Test_T.cpp
blob: cb9f63d71b5f89306d1a20f196ab8caf424b106f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// $Id$

#ifndef ACE_TESTS_STL_ALGORITHM_TEST_T_CPP
#define ACE_TESTS_STL_ALGORITHM_TEST_T_CPP

#include "test_config.h"
#include <algorithm>
#include <typeinfo>

template <typename T>
class Element_Counter
{
public:
  Element_Counter (void)
    : count_ (0)
  {

  }

  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.
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("running STL algorithm test for `%s'\n"),
              typeid (T).name ()));

  // Test the forward iterator using std::for_each.
  ACE_DEBUG ((LM_DEBUG,
              "testing forward iterator\n"));

  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;
}

#endif /* ACE_TESTS_STL_ALGORITHM_TEST_T_CPP */