xref: /llvm-project/libcxx/test/std/input.output/iostream.format/std.manip/setprecision.pass.cpp (revision f4c1258d5633fcf06385ff3fd1f4bf57ab971964)
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 // <iomanip>
10 
11 // T5 setprecision(int n);
12 
13 #include <iomanip>
14 #include <istream>
15 #include <ostream>
16 #include <cassert>
17 
18 #include "test_macros.h"
19 
20 template <class CharT>
21 struct testbuf
22     : public std::basic_streambuf<CharT>
23 {
testbuftestbuf24     testbuf() {}
25 };
26 
main(int,char **)27 int main(int, char**)
28 {
29     {
30         testbuf<char> sb;
31         std::istream is(&sb);
32         is >> std::setprecision(10);
33         assert(is.precision() == 10);
34     }
35     {
36         testbuf<char> sb;
37         std::ostream os(&sb);
38         os << std::setprecision(10);
39         assert(os.precision() == 10);
40     }
41 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
42     {
43         testbuf<wchar_t> sb;
44         std::wistream is(&sb);
45         is >> std::setprecision(10);
46         assert(is.precision() == 10);
47     }
48     {
49         testbuf<wchar_t> sb;
50         std::wostream os(&sb);
51         os << std::setprecision(10);
52         assert(os.precision() == 10);
53     }
54 #endif
55 
56   return 0;
57 }
58