Skip to content

Commit c6c60f4

Browse files
authored
Merge pull request dtolnay#1487 from dtolnay/stringview
Generate `#include <string_view>`
2 parents 4661af8 + 7f5481f commit c6c60f4

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

gen/src/builtin.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pub(super) fn write(out: &mut OutFile) {
6060
include.array = true;
6161
include.cstdint = true;
6262
include.string = true;
63+
include.string_view = true;
6364
builtin.friend_impl = true;
6465
}
6566

gen/src/include.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub(crate) struct Includes<'a> {
3636
pub ranges: bool,
3737
pub stdexcept: bool,
3838
pub string: bool,
39+
pub string_view: bool,
3940
pub type_traits: bool,
4041
pub utility: bool,
4142
pub vector: bool,
@@ -98,6 +99,7 @@ pub(super) fn write(out: &mut OutFile) {
9899
ranges,
99100
stdexcept,
100101
string,
102+
string_view,
101103
type_traits,
102104
utility,
103105
vector,
@@ -157,11 +159,6 @@ pub(super) fn write(out: &mut OutFile) {
157159
if vector && !cxx_header {
158160
writeln!(out, "#include <vector>");
159161
}
160-
if ranges && !cxx_header {
161-
writeln!(out, "#if __cplusplus >= 202002L");
162-
writeln!(out, "#include <ranges>");
163-
writeln!(out, "#endif");
164-
}
165162
if basetsd && !cxx_header {
166163
writeln!(out, "#if defined(_WIN32)");
167164
writeln!(out, "#include <basetsd.h>");
@@ -179,6 +176,16 @@ pub(super) fn write(out: &mut OutFile) {
179176
if (basetsd || sys_types) && !cxx_header {
180177
writeln!(out, "#endif");
181178
}
179+
if string_view && !cxx_header {
180+
writeln!(out, "#if __cplusplus >= 201703L");
181+
writeln!(out, "#include <string_view>");
182+
writeln!(out, "#endif");
183+
}
184+
if ranges && !cxx_header {
185+
writeln!(out, "#if __cplusplus >= 202002L");
186+
writeln!(out, "#include <ranges>");
187+
writeln!(out, "#endif");
188+
}
182189
}
183190

184191
impl<'i, 'a> Extend<&'i Include> for Includes<'a> {

0 commit comments

Comments
 (0)