Skip to content

Commit 1675115

Browse files
authored
Implement format.arguments and format.context from standard formatting library (#5217)
* Implement `format.arguments` and `format.context` from standard formatting library * fix compilation for clang-cuda and old gcc * add missing exec space annotations * final fixes (hopefully) * fix nitpicks in `__back_insert_iterator`
1 parent 6d3ffc9 commit 1675115

32 files changed

+2567
-13
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef _LIBCUDACXX___FORMAT_BUFFER_H
11+
#define _LIBCUDACXX___FORMAT_BUFFER_H
12+
13+
#include <cuda/std/detail/__config>
14+
15+
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
16+
# pragma GCC system_header
17+
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
18+
# pragma clang system_header
19+
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
20+
# pragma system_header
21+
#endif // no system header
22+
23+
#include <cuda/std/__fwd/format.h>
24+
25+
#include <cuda/std/__cccl/prologue.h>
26+
27+
_LIBCUDACXX_BEGIN_NAMESPACE_STD
28+
29+
// todo: implement __fmt_output_buffer
30+
31+
template <class _CharT>
32+
class __fmt_output_buffer
33+
{
34+
public:
35+
using value_type = _CharT;
36+
37+
_CCCL_API void push_back(_CharT __c)
38+
{
39+
_CCCL_ASSERT(false, "unimplemented __fmt_output_buffer push_back method called");
40+
(void) __c;
41+
}
42+
};
43+
44+
_LIBCUDACXX_END_NAMESPACE_STD
45+
46+
#include <cuda/std/__cccl/epilogue.h>
47+
48+
#endif // _LIBCUDACXX___FORMAT_BUFFER_H
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef _LIBCUDACXX___FORMAT_CONCEPTS_H
11+
#define _LIBCUDACXX___FORMAT_CONCEPTS_H
12+
13+
#include <cuda/std/detail/__config>
14+
15+
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
16+
# pragma GCC system_header
17+
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
18+
# pragma clang system_header
19+
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
20+
# pragma system_header
21+
#endif // no system header
22+
23+
#include <cuda/std/__concepts/concept_macros.h>
24+
#include <cuda/std/__concepts/same_as.h>
25+
#include <cuda/std/__concepts/semiregular.h>
26+
#include <cuda/std/__fwd/format.h>
27+
#include <cuda/std/__fwd/tuple.h>
28+
#include <cuda/std/__type_traits/remove_const.h>
29+
#include <cuda/std/__type_traits/remove_reference.h>
30+
#include <cuda/std/__utility/pair.h>
31+
32+
#include <cuda/std/__cccl/prologue.h>
33+
34+
_LIBCUDACXX_BEGIN_NAMESPACE_STD
35+
36+
/// The character type specializations of \ref formatter.
37+
template <class _CharT>
38+
_CCCL_CONCEPT __fmt_char_type = same_as<_CharT, char>
39+
#if _CCCL_HAS_WCHAR_T()
40+
|| same_as<_CharT, wchar_t>
41+
#endif // _CCCL_HAS_WCHAR_T()
42+
;
43+
44+
// The output iterator isn't specified. A formatter should accept any
45+
// output_iterator. This iterator is a minimal iterator to test the concept.
46+
// (Note testing for (w)format_context would be a valid choice, but requires
47+
// selecting the proper one depending on the type of _CharT.)
48+
template <class _CharT>
49+
using __fmt_iter_for _CCCL_NODEBUG_ALIAS = _CharT*;
50+
51+
template <class _Tp, class _Context, class _Formatter>
52+
_CCCL_CONCEPT __formattable_with_helper = _CCCL_REQUIRES_EXPR(
53+
(_Tp, _Context, _Formatter),
54+
_Formatter& __f,
55+
const _Formatter& __cf,
56+
_Tp&& __t,
57+
_Context __fc,
58+
basic_format_parse_context<typename _Context::char_type> __pc)(
59+
_Same_as(typename decltype(__pc)::iterator) __f.parse(__pc),
60+
_Same_as(typename _Context::iterator) __cf.format(__t, __fc));
61+
62+
template <class _Tp, class _Context, class _Formatter = typename _Context::template formatter_type<remove_const_t<_Tp>>>
63+
_CCCL_CONCEPT __formattable_with = semiregular<_Formatter> && __formattable_with_helper<_Tp, _Context, _Formatter>;
64+
65+
_LIBCUDACXX_END_NAMESPACE_STD
66+
67+
#include <cuda/std/__cccl/epilogue.h>
68+
69+
#endif // _LIBCUDACXX___FORMAT_CONCEPTS_H

0 commit comments

Comments
 (0)