LRDE Tiger Compiler  1.34a $Id: 7fef12e1f5fa43449d667a0eec1d837c40fc1202 $
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
separator.hxx
Go to the documentation of this file.
1 
6 #ifndef MISC_SEPARATOR_HXX
7 # define MISC_SEPARATOR_HXX
8 
9 # include <ostream>
10 # include <misc/deref.hh>
11 # include <misc/separator.hh>
12 
13 namespace misc
14 {
15 
16  template <class C, class S>
17  inline
18  separator<C, S>::separator(const C& c, const S& s)
19  : container_(c)
20  , separator_(s)
21  {
22  }
23 
24  template <class C, typename S>
25  inline std::ostream&
26  separator<C, S>::operator()(std::ostream& o) const
27  {
28  typedef typename C::const_iterator iter_type;
29  const iter_type begin = container_.begin();
30  const iter_type end = container_.end();
31  for (iter_type i = begin; i != end; ++i)
32  {
33  if (i != begin)
34  o << separator_;
35  o << deref << *i;
36  }
37  return o;
38  }
39 
40  template <class C, typename S>
42  separate(const C& c, const S& s)
43  {
44  return separator<C, S>(c, s);
45  }
46 
47  template <class C>
48  separator<C, char>
49  separate(const C& c)
50  {
51  return separate(c, '\n');
52  }
53 
54  template <class C, typename S>
55  inline std::ostream&
56  operator<<(std::ostream& o, const separator<C, S>& s)
57  {
58  return s(o);
59  }
60 
61 }
62 
63 #endif // !MISC_SEPARATOR_HXX