[ProfileData] Avoid repeated hash lookups (NFC) (#125464)
[llvm-project.git] / libcxx / test / std / input.output / string.streams / ostringstream / ostringstream.cons / string.alloc.pass.cpp
blob2a0e9d771d04c0640af0603a56f91e83dffd25b5
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // <sstream>
13 // template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
14 // class basic_ostringstream
16 // template <class SAlloc>
17 // basic_ostringstream(const basic_string<char_type, traits_type, SAlloc>& s, const Allocator& a)
18 // : basic_ostringstream(s, ios_base::out, a) {}
20 #include <sstream>
21 #include <cassert>
23 #include "make_string.h"
24 #include "test_allocator.h"
25 #include "test_macros.h"
26 #include "operator_hijacker.h"
28 #define STR(S) MAKE_STRING(CharT, S)
29 #define SV(S) MAKE_STRING_VIEW(CharT, S)
31 template <class CharT, class Allocator>
32 static void test(const Allocator& a) {
33 const std::basic_string<CharT> s(STR("testing"));
34 const std::basic_ostringstream<CharT, std::char_traits<CharT>, Allocator> ss(s, a);
35 assert(ss.rdbuf()->get_allocator() == a);
36 assert(ss.view() == SV("testing"));
39 int main(int, char**) {
40 test<char>(test_allocator<char>(2));
41 test<char>(operator_hijacker_allocator<char>());
42 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
43 test<wchar_t>(test_allocator<wchar_t>(2));
44 test<wchar_t>(operator_hijacker_allocator<wchar_t>());
45 #endif
46 return 0;