OTest2
A C++ testing framework
include
otest2
infixiterator.h
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2020 Ondrej Starek
3
*
4
* This file is part of OTest2.
5
*
6
* OTest2 is free software: you can redistribute it and/or modify it under
7
* the terms of the GNU Lesser General Public License as published by
8
* the Free Software Foundation, either version 3 of the License,
9
* or (at your option) any later version.
10
*
11
* OTest2 is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14
* License for more details.
15
*
16
* You should have received a copy of the GNU Lesser General Public License
17
* along with OTest2. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
20
#ifndef OTest2__INCLUDE_OTEST2_INFIXITERATOR_H_
21
#define OTest2__INCLUDE_OTEST2_INFIXITERATOR_H_
22
23
#include <assert.h>
24
#include <functional>
25
#include <iostream>
26
#include <iterator>
27
28
namespace
OTest2
{
29
30
template
<
typename
T_>
31
struct
IdentityAccessor
{
32
T_&&
operator()
(T_&& item_) {
33
return
std::forward<T_>(item_);
34
}
35
};
36
40
template
<
typename
T_,
typename
Accessor_ = IdentityAccessor<T_>,
typename
CharT_ =
char
,
typename
Traits_ = std::
char
_traits<CharT_> >
41
class
InfixIterator
42
:
public
std::iterator<std::output_iterator_tag, void, void, void, void> {
43
private
:
44
std::basic_ostream<CharT_, Traits_>* os;
45
Accessor_ accessor;
46
const
CharT_* delimiter;
47
bool
first_elem;
48
49
public
:
50
typedef
CharT_
char_type
;
51
typedef
Traits_
traits_type
;
52
typedef
std::basic_ostream<CharT_, Traits_>
ostream_type
;
53
60
InfixIterator
(
61
ostream_type
* os_,
62
const
CharT_* delim_) :
63
os(os_),
64
delimiter(delim_),
65
first_elem(true) {
66
assert(delimiter !=
nullptr
);
67
68
}
69
70
InfixIterator<T_, Accessor_, CharT_, Traits_>
&
operator=
(
71
const
T_& item_) {
72
if
(!first_elem)
73
*os << delimiter;
74
else
75
first_elem =
false
;
76
*os << accessor(item_);
77
return
*
this
;
78
}
79
80
InfixIterator<T_, Accessor_, CharT_, Traits_>
&
operator*
() {
81
return
*
this
;
82
}
83
84
InfixIterator<T_, Accessor_, CharT_, Traits_>
&
operator++
() {
85
return
*
this
;
86
}
87
88
InfixIterator<T_, Accessor_, CharT_, Traits_>
&
operator++
(
int
) {
89
return
*
this
;
90
}
91
};
92
93
}
/* -- namespace OTest2 */
94
95
#endif
/* -- OTest2__INCLUDE_OTEST2_INFIXITERATOR_H_ */
OTest2::InfixIterator::ostream_type
std::basic_ostream< CharT_, Traits_ > ostream_type
Definition:
infixiterator.h:52
OTest2::IdentityAccessor::operator()
T_ && operator()(T_ &&item_)
Definition:
infixiterator.h:32
OTest2::InfixIterator::operator=
InfixIterator< T_, Accessor_, CharT_, Traits_ > & operator=(const T_ &item_)
Definition:
infixiterator.h:70
OTest2::InfixIterator
ostream iterator with infix delimiter
Definition:
infixiterator.h:41
OTest2::IdentityAccessor
Definition:
infixiterator.h:31
OTest2::InfixIterator::operator*
InfixIterator< T_, Accessor_, CharT_, Traits_ > & operator*()
Definition:
infixiterator.h:80
OTest2
Definition:
assertbean.h:25
OTest2::InfixIterator::operator++
InfixIterator< T_, Accessor_, CharT_, Traits_ > & operator++()
Definition:
infixiterator.h:84
OTest2::InfixIterator::char_type
CharT_ char_type
Definition:
infixiterator.h:50
OTest2::InfixIterator::operator++
InfixIterator< T_, Accessor_, CharT_, Traits_ > & operator++(int)
Definition:
infixiterator.h:88
OTest2::InfixIterator::traits_type
Traits_ traits_type
Definition:
infixiterator.h:51
OTest2::InfixIterator::InfixIterator
InfixIterator(ostream_type *os_, const CharT_ *delim_)
Ctor.
Definition:
infixiterator.h:60
Generated by
1.8.17