File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 18
18
#include < valarray>
19
19
#include < vector>
20
20
21
+ #if __cplusplus >= 201703L
22
+ #include < string_view>
23
+ #endif
24
+
21
25
#include " yaml-cpp/binary.h"
22
26
#include " yaml-cpp/node/impl.h"
23
27
#include " yaml-cpp/node/iterator.h"
@@ -89,6 +93,20 @@ struct convert<char[N]> {
89
93
static Node encode (const char * rhs) { return Node (rhs); }
90
94
};
91
95
96
+ #if __cplusplus >= 201703L
97
+ template <>
98
+ struct convert <std::string_view> {
99
+ static Node encode (std::string_view rhs) { return Node (std::string (rhs)); }
100
+
101
+ static bool decode (const Node& node, std::string_view& rhs) {
102
+ if (!node.IsScalar ())
103
+ return false ;
104
+ rhs = node.Scalar ();
105
+ return true ;
106
+ }
107
+ };
108
+ #endif
109
+
92
110
template <>
93
111
struct convert <_Null> {
94
112
static Node encode (const _Null& /* rhs */ ) { return Node (); }
Original file line number Diff line number Diff line change @@ -356,6 +356,15 @@ TEST(NodeTest, ConstInteratorOnSequence) {
356
356
EXPECT_EQ (3 , count);
357
357
}
358
358
359
+ #if __cplusplus >= 201703L
360
+ TEST (NodeTest, StdStringViewAsKey) {
361
+ Node node;
362
+ std::string_view key = " username" ;
363
+ node[key] = " monkey" ;
364
+ EXPECT_EQ (" monkey" , node[key].as <std::string>());
365
+ }
366
+ #endif
367
+
359
368
TEST (NodeTest, SimpleSubkeys) {
360
369
Node node;
361
370
node[" device" ][" udid" ] = " 12345" ;
You can’t perform that action at this time.
0 commit comments