| 1 |
/////////////////////////////////////////////////////////////////////////////// |
| 2 |
// |
| 3 |
// Copyright (c) 2015 Microsoft Corporation. All rights reserved. |
| 4 |
// |
| 5 |
// This code is licensed under the MIT License (MIT). |
| 6 |
// |
| 7 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 8 |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 9 |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 10 |
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 11 |
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 12 |
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 13 |
// THE SOFTWARE. |
| 14 |
// |
| 15 |
/////////////////////////////////////////////////////////////////////////////// |
| 16 |
|
| 17 |
#ifndef GSL_ZSTRING_H |
| 18 |
#define GSL_ZSTRING_H |
| 19 |
|
| 20 |
#include "./span_ext" // for dynamic_extent |
| 21 |
|
| 22 |
#include <cstddef> // for size_t, nullptr_t |
| 23 |
|
| 24 |
namespace gsl |
| 25 |
{ |
| 26 |
// |
| 27 |
// czstring and wzstring |
| 28 |
// |
| 29 |
// These are "tag" typedefs for C-style strings (i.e. null-terminated character arrays) |
| 30 |
// that allow static analysis to help find bugs. |
| 31 |
// |
| 32 |
// There are no additional features/semantics that we can find a way to add inside the |
| 33 |
// type system for these types that will not either incur significant runtime costs or |
| 34 |
// (sometimes needlessly) break existing programs when introduced. |
| 35 |
// |
| 36 |
|
| 37 |
template <typename CharT, std::size_t Extent = dynamic_extent> |
| 38 |
using basic_zstring = CharT*; |
| 39 |
|
| 40 |
using czstring = basic_zstring<const char, dynamic_extent>; |
| 41 |
|
| 42 |
using cwzstring = basic_zstring<const wchar_t, dynamic_extent>; |
| 43 |
|
| 44 |
using cu16zstring = basic_zstring<const char16_t, dynamic_extent>; |
| 45 |
|
| 46 |
using cu32zstring = basic_zstring<const char32_t, dynamic_extent>; |
| 47 |
|
| 48 |
using zstring = basic_zstring<char, dynamic_extent>; |
| 49 |
|
| 50 |
using wzstring = basic_zstring<wchar_t, dynamic_extent>; |
| 51 |
|
| 52 |
using u16zstring = basic_zstring<char16_t, dynamic_extent>; |
| 53 |
|
| 54 |
using u32zstring = basic_zstring<char32_t, dynamic_extent>; |
| 55 |
|
| 56 |
} // namespace gsl |
| 57 |
|
| 58 |
#endif // GSL_ZSTRING_H |