1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <locale>
10 
11 // class num_put<charT, OutputIterator>
12 
13 // iter_type put(iter_type s, ios_base& iob, char_type fill, bool v) const;
14 
15 #include <locale>
16 #include <ios>
17 #include <cassert>
18 #include <streambuf>
19 #include "test_macros.h"
20 #include "test_iterators.h"
21 
22 typedef std::num_put<char, output_iterator<char*> > F;
23 
24 class my_facet
25     : public F
26 {
27 public:
my_facet(std::size_t refs=0)28     explicit my_facet(std::size_t refs = 0)
29         : F(refs) {}
30 };
31 
32 class my_numpunct
33     : public std::numpunct<char>
34 {
35 public:
my_numpunct()36     my_numpunct() : std::numpunct<char>() {}
37 
38 protected:
do_truename() const39     virtual string_type do_truename() const {return "yes";}
do_falsename() const40     virtual string_type do_falsename() const {return "no";}
41 };
42 
main(int,char **)43 int main(int, char**)
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   return 0;
102 }
103