summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/ostreambuf.iter.ops/failed.pass.cpp
blob: b52fce81344d4231953fc106bbca12b8214b176f (plain)
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
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// <iterator>

// class ostreambuf_iterator

// bool failed() const throw();

#include <iterator>
#include <sstream>
#include <cassert>

template <typename Char, typename Traits = std::char_traits<Char> >
struct my_streambuf : public std::basic_streambuf<Char,Traits> {
    typedef typename std::basic_streambuf<Char,Traits>::int_type  int_type;
    typedef typename std::basic_streambuf<Char,Traits>::char_type char_type;

    my_streambuf() {}
    int_type sputc(char_type) { return Traits::eof(); }
    };

int main()
{
    {
        my_streambuf<char> buf;
        std::ostreambuf_iterator<char> i(&buf);
        i = 'a';
        assert(i.failed());
    }
    {
        my_streambuf<wchar_t> buf;
        std::ostreambuf_iterator<wchar_t> i(&buf);
        i = L'a';
        assert(i.failed());
    }
}
OpenPOWER on IntegriCloud