Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:49

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP___FORMAT_CONTAINER_ADAPTOR_H
0011 #define _LIBCPP___FORMAT_CONTAINER_ADAPTOR_H
0012 
0013 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0014 #  pragma GCC system_header
0015 #endif
0016 
0017 #include <__config>
0018 #include <__format/concepts.h>
0019 #include <__format/formatter.h>
0020 #include <__format/range_default_formatter.h>
0021 #include <__fwd/queue.h>
0022 #include <__fwd/stack.h>
0023 #include <__ranges/ref_view.h>
0024 #include <__type_traits/is_const.h>
0025 #include <__type_traits/maybe_const.h>
0026 
0027 _LIBCPP_BEGIN_NAMESPACE_STD
0028 
0029 #if _LIBCPP_STD_VER >= 23
0030 
0031 // [container.adaptors.format] only specifies the library should provide the
0032 // formatter specializations, not which header should provide them.
0033 // Since <format> includes a lot of headers, add these headers here instead of
0034 // adding more dependencies like, locale, optinal, string, tuple, etc. to the
0035 // adaptor headers. To use the format functions users already include <format>.
0036 
0037 template <class _Adaptor, class _CharT>
0038 struct _LIBCPP_TEMPLATE_VIS __formatter_container_adaptor {
0039 private:
0040   using __maybe_const_container _LIBCPP_NODEBUG = __fmt_maybe_const<typename _Adaptor::container_type, _CharT>;
0041   using __maybe_const_adaptor _LIBCPP_NODEBUG   = __maybe_const<is_const_v<__maybe_const_container>, _Adaptor>;
0042   formatter<ranges::ref_view<__maybe_const_container>, _CharT> __underlying_;
0043 
0044 public:
0045   template <class _ParseContext>
0046   _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
0047     return __underlying_.parse(__ctx);
0048   }
0049 
0050   template <class _FormatContext>
0051   _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator
0052   format(__maybe_const_adaptor& __adaptor, _FormatContext& __ctx) const {
0053     return __underlying_.format(__adaptor.__get_container(), __ctx);
0054   }
0055 };
0056 
0057 template <class _CharT, class _Tp, formattable<_CharT> _Container>
0058 struct _LIBCPP_TEMPLATE_VIS formatter<queue<_Tp, _Container>, _CharT>
0059     : public __formatter_container_adaptor<queue<_Tp, _Container>, _CharT> {};
0060 
0061 template <class _CharT, class _Tp, class _Container, class _Compare>
0062 struct _LIBCPP_TEMPLATE_VIS formatter<priority_queue<_Tp, _Container, _Compare>, _CharT>
0063     : public __formatter_container_adaptor<priority_queue<_Tp, _Container, _Compare>, _CharT> {};
0064 
0065 template <class _CharT, class _Tp, formattable<_CharT> _Container>
0066 struct _LIBCPP_TEMPLATE_VIS formatter<stack<_Tp, _Container>, _CharT>
0067     : public __formatter_container_adaptor<stack<_Tp, _Container>, _CharT> {};
0068 
0069 #endif // _LIBCPP_STD_VER >= 23
0070 
0071 _LIBCPP_END_NAMESPACE_STD
0072 
0073 #endif // _LIBCPP___FORMAT_CONTAINER_ADAPTOR_H