You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+35-40Lines changed: 35 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,7 @@
3
3
[](https://en.wikipedia.org/wiki/C%2B%2B#Standardization) [](https://opensource.org/licenses/BSL-1.0) [](https://travis-ci.org/martinmoene/string-view-lite) [](https://ci.appveyor.com/project/martinmoene/string-view-lite) [](https://github.com/martinmoene/string-view-lite/releases) [](https://github.com/martinmoene/string-view-lite/blob/master/include/nonstd/string_view.hpp) [](https://bintray.com/conan/conan-center/string-view-lite%3A_) [](https://wandbox.org/permlink/ZfX49QqynfuQikTX) [](https://godbolt.org/z/YtxnAn)
**string-view lite** is a single-file header-only library to provide a non-owning reference to a string. The library provides a [C++17-like string_view](http://en.cppreference.com/w/cpp/string/basic_string_view) for use with C++98 and later. If available, `std::string_view` is used, unless [configured otherwise](#configuration).
52
53
53
54
**Features and properties of string-view lite** are ease of installation (single header), freedom of dependencies other than the standard library. To mimic C++17-like cooperation with `std::string`, `nonstd::string_view` provides several non-standard conversion functions. These functions may be [omitted via configuration](#configuration).
54
55
56
+
## License
55
57
56
-
License
57
-
-------
58
58
*string-view lite* is distributed under the [Boost Software License](LICENSE.txt).
59
-
60
59
61
-
Dependencies
62
-
------------
63
-
*string-view lite* has no other dependencies than the [C++ standard library](http://en.cppreference.com/w/cpp/header).
60
+
## Dependencies
64
61
62
+
*string-view lite* has no other dependencies than the [C++ standard library](http://en.cppreference.com/w/cpp/header).
65
63
66
-
Installation
67
-
------------
64
+
## Installation
68
65
69
66
*string-view lite* is a single-file header-only library. Put `string_view.hpp` in the [include](include) folder directly into the project source tree or somewhere reachable from your project.
70
67
@@ -83,22 +80,20 @@ Or, if you use the [conan package manager](https://www.conan.io/), follow these
83
80
84
81
conan install
85
82
86
-
87
-
Synopsis
88
-
--------
83
+
## Synopsis
89
84
90
85
**Contents**
91
86
[Documentation of `std::string_view`](#stdstring_view)
Depending on the compiler and C++-standard used, `nonstd::string_view` behaves less or more like `std::string_view`. To get an idea of the capabilities of `nonstd::string_view` with your configuration, look at the output of the [tests](test/string_view.t.cpp), issuing `string-view-lite.t --pass @`. For `std::string_view`, see its [documentation at cppreference](http://en.cppreference.com/w/cpp/string/basic_string_view).
99
94
100
-
C++20 extensions
101
-
----------------
95
+
## C++20 extensions
96
+
102
97
*string_view-lite* provides the following C++20 *extensions*.
Note: [[nodiscard]], constexpr and noexcept if available.
113
-
114
-
Non-standard extensions
115
-
-----------------------
108
+
109
+
## Non-standard extensions
110
+
116
111
### `string_view` literals `sv` and `_sv`
112
+
117
113
clang compilers do not allow to write `auto sv = "..."sv` with *string-view lite* under C++11. To still provide a literal operator that can be used in that case, *string-view lite* also provides `_sv`. See section [Configuration](#configuration) for how to control the presence of these operators.
118
114
119
115
The literal operators are declared in the namespace `nonstd::literals::string_view_literals`, where both `literals` and `string_view_literals` are inline namespaces, if supported. Access to these operators can be gained with using namespace `nonstd::literals`, using namespace `nonstd::string_view_literals`, and using namespace `nonstd::literals::string_view_literals`. If inline namespaces are not supported by the compiler, only the latter form is available.
120
116
121
117
### Cooperation between `std::string` and `nonstd::string_view`
118
+
122
119
*string-view lite* can provide several methods and free functions to mimic the cooperation between `std::string` and `nonstd::string_view` that exists in C++17. See the table below. Several macros allow you to control the presence of these functions, see section [Configuration](#configuration).
Define this macro to override the auto-detection of the supported C++ standard, if your compiler does not set the `__cpluplus` macro correctly.
164
159
165
160
### Select `std::string_view` or `nonstd::string_view`
161
+
166
162
At default, *string-view lite* uses `std::string_view` if it is available and lets you use it via namespace `nonstd`. You can however override this default and explicitly request to use `std::string_view` as `nonstd::string_view` or use string-view lite's `nonstd::string_view` via the following macros.
@@ -171,6 +167,7 @@ Define this to `nssv_STRING_VIEW_STD` to select `std::string_view` as `nonstd::s
171
167
Note: <b>nssv_CONFIG_SELECT_STD_STRING_VIEW</b> and <b>nssv_CONFIG_SELECT_NONSTD_STRING_VIEW</b> are deprecated and have been removed.
172
168
173
169
### Disable exceptions
170
+
174
171
-D<b>nssv\_CONFIG\_NO\_EXCEPTIONS</b>=0
175
172
Define this to 1 if you want to compile without exceptions. If not defined, the header tries and detect if exceptions have been disabled (e.g. via `-fno-exceptions`). Default is undefined.
176
173
@@ -183,6 +180,7 @@ Define this to 1 to provide literal operator `sv` to create a `string_view` from
183
180
Define this to 0 to omit literal operator `_sv` to create a `string_view` from a literal string. Default is 1.
184
181
185
182
### Omit cooperation between `std::string`–`nonstd::string_view`
183
+
186
184
At default, *string-view lite* provides several methods and free functions to mimic the cooperation between `std::string` and `nonstd::string_view` (or `std::string_view`) that exists in C++17. See section [Non-standard extensions](#non-standard-extensions). The following macros allow you to control the presence of these functions.
187
185
188
186
-D<b>nssv_CONFIG_CONVERSION_STD_STRING</b>=1
@@ -194,9 +192,8 @@ Define this to 1 to provide `std::string`– `nonstd::string_view` interoper
Define this to 1 to provide `std::string`–`nonstd::string_view` interoperability via free functions, define it to 0 to omit all said functions. This also controls the presence of these function if `std::string_view` is used. Default is undefined.
196
194
195
+
## Reported to work with
197
196
198
-
Reported to work with
199
-
---------------------
200
197
The table below mentions the compiler versions *string-view lite* is reported to work with.
- Matthew Rodusek's, @bitwizeshift. [string_view Standalone](https://github.com/bitwizeshift/string_view-standalone). GitHub.
250
245
-@satoren. [string_view for C++03 C++11 C++14](https://github.com/satoren/string_view). GitHub.
251
246
- Google Abseil [string_view](https://github.com/abseil/abseil-cpp/tree/master/absl/strings) (non-templated).
252
247
-[Search _string view c++_ on GitHub](https://github.com/search?l=C%2B%2B&q=string+view+c%2B%2B&type=Repositories&utf8=%E2%9C%93).
253
248
249
+
## Notes and references
254
250
255
-
Notes and references
256
-
--------------------
257
251
*Interface and specification*
252
+
258
253
-[string_view on cppreference](http://en.cppreference.com/w/cpp/string/basic_string_view).
259
254
-[n4659 - C++17 Working Draft: string_view](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4659.pdf#page=780).
260
255
261
256
*Presentations*
257
+
262
258
- Marshall Clow. [string_view - when to use it, and when not](https://cppcon2015.sched.com/event/3vch/stringview-when-to-use-it-and-when-not?iframe=yes&w=700&sidebar=yes&bg=no#). CppCon 2015. [video](https://youtu.be/H9gAaNRoon4), [slides](https://github.com/CppCon/CppCon2015/blob/master/Presentations/string_view/string_view%20-%20Marshall%20Clow%20-%20CppCon%202015.pdf).
263
259
- Neil MacIntosh. [A few good types: Evolving array_view and string_view for safe C++ code](https://cppcon2015.sched.com/event/3vbQ/a-few-good-types-evolving-arrayview-and-stringview-for-safe-c-code). CppCon 2015. [video](https://youtu.be/C4Z3c4Sv52U), [slides](https://github.com/CppCon/CppCon2015/blob/master/Presentations/A%20Few%20Good%20Types/A%20Few%20Good%20Types%20-%20Neil%20MacIntosh%20-%20CppCon%202015.pdf).
264
260
265
261
*Proposals*
262
+
266
263
- Jeffrey Yasskin. [n3334 - Proposing array_ref<T> and string_ref](https://wg21.link/n3334). 2012.
267
264
- Jeffrey Yasskin. [n3921 - string_view: a non-owning reference to a string, revision 7](http://wg21.link/n3921). **Adopted 2014-02**.
- Peter Sommerlad. [p0506 - use string_view for library function parameters instead of const string &/const char *](http://wg21.link/p0506). 2017.
275
272
- Daniel Krugler. [wg2946 - LWG 2758's resolution missed further corrections](https://wg21.link/lwg2946). 2017.
276
273
277
-
278
-
Appendix
279
-
--------
274
+
## Appendix
280
275
281
276
### A.1 Compile-time information
282
277
283
278
The version of *string-view lite* is available via tag `[.version]`. The following tags are available for information on the compiler and on the C++ standard library used: `[.compiler]`, `[.stdc++]`, `[.stdlanguage]` and `[.stdlibrary]`.
284
279
285
280
### A.2 string-view lite test specification
286
281
287
-
```
282
+
```Text
288
283
string_view: Allows to default construct an empty string_view
289
284
string_view: Allows to construct from pointer and size
0 commit comments