xref: /llvm-project/libcxx/include/__format/formatter.h (revision a04a6ce7726b51c4f503c8de899362bee40d4e04)
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___FORMAT_FORMATTER_H
11 #define _LIBCPP___FORMAT_FORMATTER_H
12 
13 #include <__availability>
14 #include <__config>
15 #include <__format/format_error.h>
16 #include <__format/parser_std_format_spec.h>
17 
18 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19 #pragma GCC system_header
20 #endif
21 
22 _LIBCPP_PUSH_MACROS
23 #include <__undef_macros>
24 
25 _LIBCPP_BEGIN_NAMESPACE_STD
26 
27 #if _LIBCPP_STD_VER > 17
28 
29 // TODO FMT Remove this once we require compilers with proper C++20 support.
30 // If the compiler has no concepts support, the format header will be disabled.
31 // Without concepts support enable_if needs to be used and that too much effort
32 // to support compilers with partial C++20 support.
33 #if !defined(_LIBCPP_HAS_NO_CONCEPTS)
34 
35 // Currently not implemented specializations throw an exception when used. This
36 // does not conform to the Standard. However not all Standard defined formatters
37 // have been implemented yet. Until that time the current behavior is intended.
38 // TODO FMT Disable the default template.
39 template <class _Tp, class _CharT>
40 struct _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT formatter {
41   _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI auto parse(auto& __parse_ctx)
42       -> decltype(__parse_ctx.begin()) {
43     __throw();
44   }
45 
46   _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI auto format(_Tp, auto& __ctx)
47       -> decltype(__ctx.out()) {
48     __throw();
49   }
50 
51 private:
52   _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw() {
53     __throw_format_error("Argument type not implemented yet");
54   }
55 };
56 
57 #endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
58 
59 #endif //_LIBCPP_STD_VER > 17
60 
61 _LIBCPP_END_NAMESPACE_STD
62 
63 _LIBCPP_POP_MACROS
64 
65 #endif // _LIBCPP___FORMAT_FORMATTER_H
66