1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // template<class charT, class traits, class Allocator>
12 // basic_istream<charT,traits>&
13 // getline(basic_istream<charT,traits>& is,
14 // basic_string<charT,traits,Allocator>& str, charT delim);
20 #include "min_allocator.h"
21 #include "test_macros.h"
23 template <template <class> class Alloc
>
25 using S
= std::basic_string
<char, std::char_traits
<char>, Alloc
<char> >;
26 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
27 using WS
= std::basic_string
<wchar_t, std::char_traits
<wchar_t>, Alloc
<wchar_t> >;
31 std::istringstream
in(" abc* def** ghij");
33 std::getline(in
, s
, '*');
36 std::getline(in
, s
, '*');
39 std::getline(in
, s
, '*');
42 std::getline(in
, s
, '*');
46 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
48 std::wistringstream
in(L
" abc* def** ghij");
49 WS
s(L
"initial text");
50 std::getline(in
, s
, L
'*');
53 std::getline(in
, s
, L
'*');
56 std::getline(in
, s
, L
'*');
59 std::getline(in
, s
, L
'*');
61 assert(s
== L
" ghij");
65 #ifndef TEST_HAS_NO_EXCEPTIONS
67 std::basic_stringbuf
<char> sb("hello");
68 std::basic_istream
<char> is(&sb
);
69 is
.exceptions(std::ios::eofbit
);
74 std::getline(is
, s
, '\n');
75 } catch (std::ios::failure
const&) {
85 # ifndef TEST_HAS_NO_WIDE_CHARACTERS
87 std::basic_stringbuf
<wchar_t> sb(L
"hello");
88 std::basic_istream
<wchar_t> is(&sb
);
89 is
.exceptions(std::ios::eofbit
);
94 std::getline(is
, s
, L
'\n');
95 } catch (std::ios::failure
const&) {
103 assert(s
== L
"hello");
105 # endif // TEST_HAS_NO_WIDE_CHARACTERS
107 std::basic_stringbuf
<char> sb
;
108 std::basic_istream
<char> is(&sb
);
109 is
.exceptions(std::ios::failbit
);
114 std::getline(is
, s
, '\n');
115 } catch (std::ios::failure
const&) {
125 # ifndef TEST_HAS_NO_WIDE_CHARACTERS
127 std::basic_stringbuf
<wchar_t> sb
;
128 std::basic_istream
<wchar_t> is(&sb
);
129 is
.exceptions(std::ios::failbit
);
134 std::getline(is
, s
, L
'\n');
135 } catch (std::ios::failure
const&) {
145 # endif // TEST_HAS_NO_WIDE_CHARACTERS
146 #endif // TEST_HAS_NO_EXCEPTIONS
149 int main(int, char**) {
150 test_string
<std::allocator
>();
151 #if TEST_STD_VER >= 11
152 test_string
<min_allocator
>();