statically_widen.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP___CHRONO_STATICALLY_WIDEN_H
  10. #define _LIBCPP___CHRONO_STATICALLY_WIDEN_H
  11. // Implements the STATICALLY-WIDEN exposition-only function. ([time.general]/2)
  12. #include <__concepts/same_as.h>
  13. #include <__config>
  14. #include <__format/concepts.h>
  15. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  16. # pragma GCC system_header
  17. #endif
  18. _LIBCPP_BEGIN_NAMESPACE_STD
  19. #if _LIBCPP_STD_VER > 17
  20. # ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  21. template <__fmt_char_type _CharT>
  22. _LIBCPP_HIDE_FROM_ABI constexpr const _CharT* __statically_widen(const char* __str, const wchar_t* __wstr) {
  23. if constexpr (same_as<_CharT, char>)
  24. return __str;
  25. else
  26. return __wstr;
  27. }
  28. # define _LIBCPP_STATICALLY_WIDEN(_CharT, __str) ::std::__statically_widen<_CharT>(__str, L##__str)
  29. # else // _LIBCPP_HAS_NO_WIDE_CHARACTERS
  30. // Without this indirection the unit test test/libcxx/modules_include.sh.cpp
  31. // fails for the CI build "No wide characters". This seems like a bug.
  32. // TODO FMT investigate why this is needed.
  33. template <__fmt_char_type _CharT>
  34. _LIBCPP_HIDE_FROM_ABI constexpr const _CharT* __statically_widen(const char* __str) {
  35. return __str;
  36. }
  37. # define _LIBCPP_STATICALLY_WIDEN(_CharT, __str) ::std::__statically_widen<_CharT>(__str)
  38. # endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
  39. #endif //_LIBCPP_STD_VER > 17
  40. _LIBCPP_END_NAMESPACE_STD
  41. #endif // _LIBCPP___CHRONO_STATICALLY_WIDEN_H