File: function_output_iterator.qbk

package info (click to toggle)
boost1.35 1.35.0-5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 203,856 kB
  • ctags: 337,867
  • sloc: cpp: 938,683; xml: 56,847; ansic: 41,589; python: 18,999; sh: 11,566; makefile: 664; perl: 494; yacc: 456; asm: 353; csh: 6
file content (100 lines) | stat: -rw-r--r-- 2,428 bytes parent folder | download | duplicates (5)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

[section:function_output Function Output Iterator]

The function output iterator adaptor makes it easier to create custom
output iterators. The adaptor takes a unary function and creates a
model of Output Iterator. Each item assigned to the output iterator is
passed as an argument to the unary function.  The motivation for this
iterator is that creating a conforming output iterator is non-trivial,
particularly because the proper implementation usually requires a
proxy object.

[h2 Example]

    struct string_appender
    {
        string_appender(std::string& s)
            : m_str(&s)
        {}

        void operator()(const std::string& x) const
        {
            *m_str += x;
        }

        std::string* m_str;
    };

    int main(int, char*[])
    {
      std::vector<std::string> x;
      x.push_back("hello");
      x.push_back(" ");
      x.push_back("world");
      x.push_back("!");

      std::string s = "";
      std::copy(x.begin(), x.end(), 
		boost::make_function_output_iterator(string_appender(s)));

      std::cout << s << std::endl;

      return 0;
    }

[h2 Reference]

[h3 Synopsis]

  template <class UnaryFunction>
  class function_output_iterator {
  public:
    typedef std::output_iterator_tag iterator_category;
    typedef void                     value_type;
    typedef void                     difference_type;
    typedef void                     pointer;
    typedef void                     reference;

    explicit function_output_iterator();

    explicit function_output_iterator(const UnaryFunction& f);

    /* see below */ operator*();
    function_output_iterator& operator++();
    function_output_iterator& operator++(int);
  private:
    UnaryFunction m_f;     // exposition only
  };

[h3 Requirements]

`UnaryFunction` must be Assignable and Copy Constructible.  

[h3 Concepts]

`function_output_iterator` is a model of the Writable and
Incrementable Iterator concepts.

[h3 Operations]

  explicit function_output_iterator(const UnaryFunction& f = UnaryFunction());

[*Effects: ] Constructs an instance of `function_output_iterator` 
  with `m_f` constructed from `f`.

  unspecified_type operator*();

[*Returns: ] An object `r` of unspecified type such that `r = t`
  is equivalent to `m_f(t)` for all `t`.
  

  function_output_iterator& operator++();

[*Returns: ] `*this`.


  function_output_iterator& operator++(int);

[*Returns: ] `*this`.

[endsect]