stream_copy

概要:ストリームのコピー
ソース:stream_copy.hpp (ASCII CR/LF)
 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
// copy(Container to OutputIterator)
// template< class TContainer, class TOutputIterator >
// TOutputIterator copy(const TContainer& C_, TOutputIterator O_)
// {
//  return std::copy(std::begin(C_), std::end(C_), O_);
// }
// copy(istream to OutputIterator)
template< class TChar, class TTraits, class TOutputIterator > inline
TOutputIterator stream_copy(std::basic_istream<TChar, TTraits>& I_, TOutputIterator O_)
{
    return std::copy(
        (std::istreambuf_iterator<TChar>(I_)),
        (std::istreambuf_iterator<TChar>()),
        O_
    );
}
// copy(istream to ostream)
template< class TCharI, class TTraitsI, class TCharO, class TTraitsO > inline
std::ostream_iterator<TCharO, TCharO> stream_copy(
    std::basic_istream<TCharI, TTraitsI>& I_,
    std::basic_ostream<TCharO, TTraitsO>& O_,
    const TCharO* delimiter
) {
//  I_ << O_.rdbuf(); return O_;
    return std::copy(
        (std::istreambuf_iterator<TCharI>(I_)),
        (std::istreambuf_iterator<TCharI>()), 
        (std::ostream_iterator<TCharI, TCharO>(O_, delimiter))
    );
}
// copy(range to ostream)
template< class TInputIterator, class TChar, class TTraits > inline
std::ostream_iterator<typename std::iterator_traits<TInputIterator>::value_type, TChar>& stream_copy(
    TInputIterator F_, 
    TInputIterator L_,
    std::basic_ostream<TChar, TTraits>& O_,
    const TChar* delimiter
) {
    return std::copy(
        F_,
        L_,
        (std::ostream_iterator<
                typename std::iterator_traits<TInputIterator>::value_type,
                TChar
            >(O_, delimiter)
        )
    );
}
// copy(Container to ostream)
template< class TContainer, class TChar, class TTraits > inline
std::ostream_iterator<typename TContainer::value_type, TChar> stream_copy(
    TContainer C_,
    std::basic_ostream<TChar, TTraits>& O_,
    const TChar* delimiter
) {
    return std::copy(
        std::begin(C_),
        std::end(C_),
        (std::ostream_iterator<typename TContainer::value_type, TChar>(O_, delimiter))
    );
}