1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <locale>
11
12// class num_put<charT, OutputIterator>
13
14// iter_type put(iter_type s, ios_base& iob, char_type fill, bool v) const;
15
16#include <locale>
17#include <ios>
18#include <cassert>
19#include <streambuf>
20#include "test_iterators.h"
21
22typedef std::num_put<char, output_iterator<char*> > F;
23
24class my_facet
25    : public F
26{
27public:
28    explicit my_facet(std::size_t refs = 0)
29        : F(refs) {}
30};
31
32class my_numpunct
33    : public std::numpunct<char>
34{
35public:
36    my_numpunct() : std::numpunct<char>() {}
37
38protected:
39    virtual string_type do_truename() const {return "yes";}
40    virtual string_type do_falsename() const {return "no";}
41};
42
43int main()
44{
45    const my_facet f(1);
46    {
47        std::ios ios(0);
48        {
49            bool v = false;
50            char str[50];
51            output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
52            std::string ex(str, iter.base());
53            assert(ex == "0");
54        }
55        {
56            bool v = true;
57            char str[50];
58            output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
59            std::string ex(str, iter.base());
60            assert(ex == "1");
61        }
62    }
63    {
64        std::ios ios(0);
65        boolalpha(ios);
66        {
67            bool v = false;
68            char str[50];
69            output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
70            std::string ex(str, iter.base());
71            assert(ex == "false");
72        }
73        {
74            bool v = true;
75            char str[50];
76            output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
77            std::string ex(str, iter.base());
78            assert(ex == "true");
79        }
80    }
81    {
82        std::ios ios(0);
83        boolalpha(ios);
84        ios.imbue(std::locale(std::locale::classic(), new my_numpunct));
85        {
86            bool v = false;
87            char str[50];
88            output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
89            std::string ex(str, iter.base());
90            assert(ex == "no");
91        }
92        {
93            bool v = true;
94            char str[50];
95            output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
96            std::string ex(str, iter.base());
97            assert(ex == "yes");
98        }
99    }
100}
101