zstring 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #ifndef GSL_ZSTRING_H
  17. #define GSL_ZSTRING_H
  18. #include "span_ext" // for dynamic_extent
  19. #include <cstddef> // for size_t, nullptr_t
  20. namespace gsl
  21. {
  22. //
  23. // czstring and wzstring
  24. //
  25. // These are "tag" typedefs for C-style strings (i.e. null-terminated character arrays)
  26. // that allow static analysis to help find bugs.
  27. //
  28. // There are no additional features/semantics that we can find a way to add inside the
  29. // type system for these types that will not either incur significant runtime costs or
  30. // (sometimes needlessly) break existing programs when introduced.
  31. //
  32. template <typename CharT, std::size_t Extent = dynamic_extent>
  33. using basic_zstring = CharT*;
  34. using czstring = basic_zstring<const char, dynamic_extent>;
  35. using cwzstring = basic_zstring<const wchar_t, dynamic_extent>;
  36. using cu16zstring = basic_zstring<const char16_t, dynamic_extent>;
  37. using cu32zstring = basic_zstring<const char32_t, dynamic_extent>;
  38. using zstring = basic_zstring<char, dynamic_extent>;
  39. using wzstring = basic_zstring<wchar_t, dynamic_extent>;
  40. using u16zstring = basic_zstring<char16_t, dynamic_extent>;
  41. using u32zstring = basic_zstring<char32_t, dynamic_extent>;
  42. } // namespace gsl
  43. #endif // GSL_ZSTRING_H