xref: /freebsd/contrib/llvm-project/libcxx/include/__chrono/statically_widen.h (revision 2e3507c25e42292b45a5482e116d278f5515d04d)
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 
10 #ifndef _LIBCPP___CHRONO_STATICALLY_WIDEN_H
11 #define _LIBCPP___CHRONO_STATICALLY_WIDEN_H
12 
13 // Implements the STATICALLY-WIDEN exposition-only function. ([time.general]/2)
14 
15 #include <__concepts/same_as.h>
16 #include <__config>
17 #include <__format/concepts.h>
18 
19 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20 #  pragma GCC system_header
21 #endif
22 
23 _LIBCPP_BEGIN_NAMESPACE_STD
24 
25 #if _LIBCPP_STD_VER >= 20
26 
27 #  ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
28 template <__fmt_char_type _CharT>
29 _LIBCPP_HIDE_FROM_ABI constexpr const _CharT* __statically_widen(const char* __str, const wchar_t* __wstr) {
30   if constexpr (same_as<_CharT, char>)
31     return __str;
32   else
33     return __wstr;
34 }
35 #    define _LIBCPP_STATICALLY_WIDEN(_CharT, __str) ::std::__statically_widen<_CharT>(__str, L##__str)
36 #  else // _LIBCPP_HAS_NO_WIDE_CHARACTERS
37 
38 // Without this indirection the unit test test/libcxx/modules_include.sh.cpp
39 // fails for the CI build "No wide characters". This seems like a bug.
40 // TODO FMT investigate why this is needed.
41 template <__fmt_char_type _CharT>
42 _LIBCPP_HIDE_FROM_ABI constexpr const _CharT* __statically_widen(const char* __str) {
43   return __str;
44 }
45 #    define _LIBCPP_STATICALLY_WIDEN(_CharT, __str) ::std::__statically_widen<_CharT>(__str)
46 #  endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
47 
48 #endif //_LIBCPP_STD_VER >= 20
49 
50 _LIBCPP_END_NAMESPACE_STD
51 
52 #endif // _LIBCPP___CHRONO_STATICALLY_WIDEN_H
53