| 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, cpp17_output_iterator<char*> > F; |
| 23 | |
| 24 | class my_facet : public F { |
| 25 | public: |
| 26 | explicit my_facet(std::size_t refs = 0) : F(refs) {} |
| 27 | }; |
| 28 | |
| 29 | class my_numpunct : public std::numpunct<char> { |
| 30 | public: |
| 31 | my_numpunct() : std::numpunct<char>() {} |
| 32 | |
| 33 | protected: |
| 34 | virtual string_type do_truename() const { return "yes" ; } |
| 35 | virtual string_type do_falsename() const { return "no" ; } |
| 36 | }; |
| 37 | |
| 38 | int main(int, char**) { |
| 39 | const my_facet f(1); |
| 40 | { |
| 41 | std::ios ios(0); |
| 42 | { |
| 43 | bool v = false; |
| 44 | char str[50]; |
| 45 | cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v); |
| 46 | std::string ex(str, base(iter)); |
| 47 | assert(ex == "0" ); |
| 48 | } |
| 49 | { |
| 50 | bool v = true; |
| 51 | char str[50]; |
| 52 | cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v); |
| 53 | std::string ex(str, base(iter)); |
| 54 | assert(ex == "1" ); |
| 55 | } |
| 56 | } |
| 57 | { |
| 58 | std::ios ios(0); |
| 59 | std::boolalpha(base&: ios); |
| 60 | { |
| 61 | bool v = false; |
| 62 | char str[50]; |
| 63 | cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v); |
| 64 | std::string ex(str, base(iter)); |
| 65 | assert(ex == "false" ); |
| 66 | } |
| 67 | { |
| 68 | bool v = true; |
| 69 | char str[50]; |
| 70 | cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v); |
| 71 | std::string ex(str, base(iter)); |
| 72 | assert(ex == "true" ); |
| 73 | } |
| 74 | } |
| 75 | { |
| 76 | std::ios ios(0); |
| 77 | std::boolalpha(base&: ios); |
| 78 | ios.imbue(loc: std::locale(std::locale::classic(), new my_numpunct)); |
| 79 | { |
| 80 | bool v = false; |
| 81 | char str[50]; |
| 82 | cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v); |
| 83 | std::string ex(str, base(iter)); |
| 84 | assert(ex == "no" ); |
| 85 | } |
| 86 | { |
| 87 | bool v = true; |
| 88 | char str[50]; |
| 89 | cpp17_output_iterator<char*> iter = f.put(cpp17_output_iterator<char*>(str), ios, '*', v); |
| 90 | std::string ex(str, base(iter)); |
| 91 | assert(ex == "yes" ); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | return 0; |
| 96 | } |
| 97 | |