File: test_accum_iter.cc

package info (click to toggle)
libsigc%2B%2B-2.0 2.12.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,432 kB
  • sloc: cpp: 4,132; xml: 339; python: 196; makefile: 192; sh: 5
file content (52 lines) | stat: -rw-r--r-- 1,127 bytes parent folder | download | duplicates (6)
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
#include "testutilities.h"
#include <sigc++/sigc++.h>
#include <sstream>
#include <algorithm>
#include <functional>
#include <cstdlib>

namespace
{
std::ostringstream result_stream;

int ident(int i)
{
  return i;
}

template<typename T>
struct min_accum
{
  typedef T result_type;

  template<class I>
#ifndef SIGC_HAVE_SUN_REVERSE_ITERATOR
  typename std::iterator_traits<I>::value_type operator()(I i1, I i2)
#else
  typename I::value_type operator()(I i1, I i2)
#endif
  {
    return *std::min_element(i1, i2);
  }
};

} // end anonymous namespace

int main(int argc, char* argv[])
{
  auto util = TestUtilities::get_instance();

  if (!util->check_command_args(argc, argv))
    return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;

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

  result_stream << signal();
  util->check_result(result_stream, "1");

  return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
}