You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. // Formatting library for C++ - experimental format string compilation
  2. //
  3. // Copyright (c) 2012 - present, Victor Zverovich and fmt contributors
  4. // All rights reserved.
  5. //
  6. // For the license information refer to format.h.
  7. #ifndef FMT_COMPILE_H_
  8. #define FMT_COMPILE_H_
  9. #include "format.h"
  10. FMT_BEGIN_NAMESPACE
  11. namespace detail {
  12. template <typename Char, typename InputIt>
  13. FMT_CONSTEXPR inline counting_iterator copy_str(InputIt begin, InputIt end,
  14. counting_iterator it) {
  15. return it + (end - begin);
  16. }
  17. template <typename OutputIt> class truncating_iterator_base {
  18. protected:
  19. OutputIt out_;
  20. size_t limit_;
  21. size_t count_ = 0;
  22. truncating_iterator_base() : out_(), limit_(0) {}
  23. truncating_iterator_base(OutputIt out, size_t limit)
  24. : out_(out), limit_(limit) {}
  25. public:
  26. using iterator_category = std::output_iterator_tag;
  27. using value_type = typename std::iterator_traits<OutputIt>::value_type;
  28. using difference_type = std::ptrdiff_t;
  29. using pointer = void;
  30. using reference = void;
  31. FMT_UNCHECKED_ITERATOR(truncating_iterator_base);
  32. OutputIt base() const { return out_; }
  33. size_t count() const { return count_; }
  34. };
  35. // An output iterator that truncates the output and counts the number of objects
  36. // written to it.
  37. template <typename OutputIt,
  38. typename Enable = typename std::is_void<
  39. typename std::iterator_traits<OutputIt>::value_type>::type>
  40. class truncating_iterator;
  41. template <typename OutputIt>
  42. class truncating_iterator<OutputIt, std::false_type>
  43. : public truncating_iterator_base<OutputIt> {
  44. mutable typename truncating_iterator_base<OutputIt>::value_type blackhole_;
  45. public:
  46. using value_type = typename truncating_iterator_base<OutputIt>::value_type;
  47. truncating_iterator() = default;
  48. truncating_iterator(OutputIt out, size_t limit)
  49. : truncating_iterator_base<OutputIt>(out, limit) {}
  50. truncating_iterator& operator++() {
  51. if (this->count_++ < this->limit_) ++this->out_;
  52. return *this;
  53. }
  54. truncating_iterator operator++(int) {
  55. auto it = *this;
  56. ++*this;
  57. return it;
  58. }
  59. value_type& operator*() const {
  60. return this->count_ < this->limit_ ? *this->out_ : blackhole_;
  61. }
  62. };
  63. template <typename OutputIt>
  64. class truncating_iterator<OutputIt, std::true_type>
  65. : public truncating_iterator_base<OutputIt> {
  66. public:
  67. truncating_iterator() = default;
  68. truncating_iterator(OutputIt out, size_t limit)
  69. : truncating_iterator_base<OutputIt>(out, limit) {}
  70. template <typename T> truncating_iterator& operator=(T val) {
  71. if (this->count_++ < this->limit_) *this->out_++ = val;
  72. return *this;
  73. }
  74. truncating_iterator& operator++() { return *this; }
  75. truncating_iterator& operator++(int) { return *this; }
  76. truncating_iterator& operator*() { return *this; }
  77. };
  78. // A compile-time string which is compiled into fast formatting code.
  79. class compiled_string {};
  80. template <typename S>
  81. struct is_compiled_string : std::is_base_of<compiled_string, S> {};
  82. /**
  83. \rst
  84. Converts a string literal *s* into a format string that will be parsed at
  85. compile time and converted into efficient formatting code. Requires C++17
  86. ``constexpr if`` compiler support.
  87. **Example**::
  88. // Converts 42 into std::string using the most efficient method and no
  89. // runtime format string processing.
  90. std::string s = fmt::format(FMT_COMPILE("{}"), 42);
  91. \endrst
  92. */
  93. #if defined(__cpp_if_constexpr) && defined(__cpp_return_type_deduction)
  94. # define FMT_COMPILE(s) \
  95. FMT_STRING_IMPL(s, fmt::detail::compiled_string, explicit)
  96. #else
  97. # define FMT_COMPILE(s) FMT_STRING(s)
  98. #endif
  99. #if FMT_USE_NONTYPE_TEMPLATE_ARGS
  100. template <typename Char, size_t N,
  101. fmt::detail_exported::fixed_string<Char, N> Str>
  102. struct udl_compiled_string : compiled_string {
  103. using char_type = Char;
  104. explicit constexpr operator basic_string_view<char_type>() const {
  105. return {Str.data, N - 1};
  106. }
  107. };
  108. #endif
  109. template <typename T, typename... Tail>
  110. const T& first(const T& value, const Tail&...) {
  111. return value;
  112. }
  113. #if defined(__cpp_if_constexpr) && defined(__cpp_return_type_deduction)
  114. template <typename... Args> struct type_list {};
  115. // Returns a reference to the argument at index N from [first, rest...].
  116. template <int N, typename T, typename... Args>
  117. constexpr const auto& get([[maybe_unused]] const T& first,
  118. [[maybe_unused]] const Args&... rest) {
  119. static_assert(N < 1 + sizeof...(Args), "index is out of bounds");
  120. if constexpr (N == 0)
  121. return first;
  122. else
  123. return detail::get<N - 1>(rest...);
  124. }
  125. template <typename Char, typename... Args>
  126. constexpr int get_arg_index_by_name(basic_string_view<Char> name,
  127. type_list<Args...>) {
  128. return get_arg_index_by_name<Args...>(name);
  129. }
  130. template <int N, typename> struct get_type_impl;
  131. template <int N, typename... Args> struct get_type_impl<N, type_list<Args...>> {
  132. using type =
  133. remove_cvref_t<decltype(detail::get<N>(std::declval<Args>()...))>;
  134. };
  135. template <int N, typename T>
  136. using get_type = typename get_type_impl<N, T>::type;
  137. template <typename T> struct is_compiled_format : std::false_type {};
  138. template <typename Char> struct text {
  139. basic_string_view<Char> data;
  140. using char_type = Char;
  141. template <typename OutputIt, typename... Args>
  142. constexpr OutputIt format(OutputIt out, const Args&...) const {
  143. return write<Char>(out, data);
  144. }
  145. };
  146. template <typename Char>
  147. struct is_compiled_format<text<Char>> : std::true_type {};
  148. template <typename Char>
  149. constexpr text<Char> make_text(basic_string_view<Char> s, size_t pos,
  150. size_t size) {
  151. return {{&s[pos], size}};
  152. }
  153. template <typename Char> struct code_unit {
  154. Char value;
  155. using char_type = Char;
  156. template <typename OutputIt, typename... Args>
  157. constexpr OutputIt format(OutputIt out, const Args&...) const {
  158. return write<Char>(out, value);
  159. }
  160. };
  161. // This ensures that the argument type is convertible to `const T&`.
  162. template <typename T, int N, typename... Args>
  163. constexpr const T& get_arg_checked(const Args&... args) {
  164. const auto& arg = detail::get<N>(args...);
  165. if constexpr (detail::is_named_arg<remove_cvref_t<decltype(arg)>>()) {
  166. return arg.value;
  167. } else {
  168. return arg;
  169. }
  170. }
  171. template <typename Char>
  172. struct is_compiled_format<code_unit<Char>> : std::true_type {};
  173. // A replacement field that refers to argument N.
  174. template <typename Char, typename T, int N> struct field {
  175. using char_type = Char;
  176. template <typename OutputIt, typename... Args>
  177. constexpr OutputIt format(OutputIt out, const Args&... args) const {
  178. return write<Char>(out, get_arg_checked<T, N>(args...));
  179. }
  180. };
  181. template <typename Char, typename T, int N>
  182. struct is_compiled_format<field<Char, T, N>> : std::true_type {};
  183. // A replacement field that refers to argument with name.
  184. template <typename Char> struct runtime_named_field {
  185. using char_type = Char;
  186. basic_string_view<Char> name;
  187. template <typename OutputIt, typename T>
  188. constexpr static bool try_format_argument(
  189. OutputIt& out,
  190. // [[maybe_unused]] due to unused-but-set-parameter warning in GCC 7,8,9
  191. [[maybe_unused]] basic_string_view<Char> arg_name, const T& arg) {
  192. if constexpr (is_named_arg<typename std::remove_cv<T>::type>::value) {
  193. if (arg_name == arg.name) {
  194. out = write<Char>(out, arg.value);
  195. return true;
  196. }
  197. }
  198. return false;
  199. }
  200. template <typename OutputIt, typename... Args>
  201. constexpr OutputIt format(OutputIt out, const Args&... args) const {
  202. bool found = (try_format_argument(out, name, args) || ...);
  203. if (!found) {
  204. FMT_THROW(format_error("argument with specified name is not found"));
  205. }
  206. return out;
  207. }
  208. };
  209. template <typename Char>
  210. struct is_compiled_format<runtime_named_field<Char>> : std::true_type {};
  211. // A replacement field that refers to argument N and has format specifiers.
  212. template <typename Char, typename T, int N> struct spec_field {
  213. using char_type = Char;
  214. formatter<T, Char> fmt;
  215. template <typename OutputIt, typename... Args>
  216. constexpr FMT_INLINE OutputIt format(OutputIt out,
  217. const Args&... args) const {
  218. const auto& vargs =
  219. fmt::make_format_args<basic_format_context<OutputIt, Char>>(args...);
  220. basic_format_context<OutputIt, Char> ctx(out, vargs);
  221. return fmt.format(get_arg_checked<T, N>(args...), ctx);
  222. }
  223. };
  224. template <typename Char, typename T, int N>
  225. struct is_compiled_format<spec_field<Char, T, N>> : std::true_type {};
  226. template <typename L, typename R> struct concat {
  227. L lhs;
  228. R rhs;
  229. using char_type = typename L::char_type;
  230. template <typename OutputIt, typename... Args>
  231. constexpr OutputIt format(OutputIt out, const Args&... args) const {
  232. out = lhs.format(out, args...);
  233. return rhs.format(out, args...);
  234. }
  235. };
  236. template <typename L, typename R>
  237. struct is_compiled_format<concat<L, R>> : std::true_type {};
  238. template <typename L, typename R>
  239. constexpr concat<L, R> make_concat(L lhs, R rhs) {
  240. return {lhs, rhs};
  241. }
  242. struct unknown_format {};
  243. template <typename Char>
  244. constexpr size_t parse_text(basic_string_view<Char> str, size_t pos) {
  245. for (size_t size = str.size(); pos != size; ++pos) {
  246. if (str[pos] == '{' || str[pos] == '}') break;
  247. }
  248. return pos;
  249. }
  250. template <typename Args, size_t POS, int ID, typename S>
  251. constexpr auto compile_format_string(S format_str);
  252. template <typename Args, size_t POS, int ID, typename T, typename S>
  253. constexpr auto parse_tail(T head, S format_str) {
  254. if constexpr (POS !=
  255. basic_string_view<typename S::char_type>(format_str).size()) {
  256. constexpr auto tail = compile_format_string<Args, POS, ID>(format_str);
  257. if constexpr (std::is_same<remove_cvref_t<decltype(tail)>,
  258. unknown_format>())
  259. return tail;
  260. else
  261. return make_concat(head, tail);
  262. } else {
  263. return head;
  264. }
  265. }
  266. template <typename T, typename Char> struct parse_specs_result {
  267. formatter<T, Char> fmt;
  268. size_t end;
  269. int next_arg_id;
  270. };
  271. enum { manual_indexing_id = -1 };
  272. template <typename T, typename Char>
  273. constexpr parse_specs_result<T, Char> parse_specs(basic_string_view<Char> str,
  274. size_t pos, int next_arg_id) {
  275. str.remove_prefix(pos);
  276. auto ctx =
  277. compile_parse_context<Char>(str, max_value<int>(), nullptr, next_arg_id);
  278. auto f = formatter<T, Char>();
  279. auto end = f.parse(ctx);
  280. return {f, pos + fmt::detail::to_unsigned(end - str.data()),
  281. next_arg_id == 0 ? manual_indexing_id : ctx.next_arg_id()};
  282. }
  283. template <typename Char> struct arg_id_handler {
  284. arg_ref<Char> arg_id;
  285. constexpr int on_auto() {
  286. FMT_ASSERT(false, "handler cannot be used with automatic indexing");
  287. return 0;
  288. }
  289. constexpr int on_index(int id) {
  290. arg_id = arg_ref<Char>(id);
  291. return 0;
  292. }
  293. constexpr int on_name(basic_string_view<Char> id) {
  294. arg_id = arg_ref<Char>(id);
  295. return 0;
  296. }
  297. };
  298. template <typename Char> struct parse_arg_id_result {
  299. arg_ref<Char> arg_id;
  300. const Char* arg_id_end;
  301. };
  302. template <int ID, typename Char>
  303. constexpr auto parse_arg_id(const Char* begin, const Char* end) {
  304. auto handler = arg_id_handler<Char>{arg_ref<Char>{}};
  305. auto arg_id_end = parse_arg_id(begin, end, handler);
  306. return parse_arg_id_result<Char>{handler.arg_id, arg_id_end};
  307. }
  308. template <typename T, typename Enable = void> struct field_type {
  309. using type = remove_cvref_t<T>;
  310. };
  311. template <typename T>
  312. struct field_type<T, enable_if_t<detail::is_named_arg<T>::value>> {
  313. using type = remove_cvref_t<decltype(T::value)>;
  314. };
  315. template <typename T, typename Args, size_t END_POS, int ARG_INDEX, int NEXT_ID,
  316. typename S>
  317. constexpr auto parse_replacement_field_then_tail(S format_str) {
  318. using char_type = typename S::char_type;
  319. constexpr auto str = basic_string_view<char_type>(format_str);
  320. constexpr char_type c = END_POS != str.size() ? str[END_POS] : char_type();
  321. if constexpr (c == '}') {
  322. return parse_tail<Args, END_POS + 1, NEXT_ID>(
  323. field<char_type, typename field_type<T>::type, ARG_INDEX>(),
  324. format_str);
  325. } else if constexpr (c != ':') {
  326. FMT_THROW(format_error("expected ':'"));
  327. } else {
  328. constexpr auto result = parse_specs<typename field_type<T>::type>(
  329. str, END_POS + 1, NEXT_ID == manual_indexing_id ? 0 : NEXT_ID);
  330. if constexpr (result.end >= str.size() || str[result.end] != '}') {
  331. FMT_THROW(format_error("expected '}'"));
  332. return 0;
  333. } else {
  334. return parse_tail<Args, result.end + 1, result.next_arg_id>(
  335. spec_field<char_type, typename field_type<T>::type, ARG_INDEX>{
  336. result.fmt},
  337. format_str);
  338. }
  339. }
  340. }
  341. // Compiles a non-empty format string and returns the compiled representation
  342. // or unknown_format() on unrecognized input.
  343. template <typename Args, size_t POS, int ID, typename S>
  344. constexpr auto compile_format_string(S format_str) {
  345. using char_type = typename S::char_type;
  346. constexpr auto str = basic_string_view<char_type>(format_str);
  347. if constexpr (str[POS] == '{') {
  348. if constexpr (POS + 1 == str.size())
  349. FMT_THROW(format_error("unmatched '{' in format string"));
  350. if constexpr (str[POS + 1] == '{') {
  351. return parse_tail<Args, POS + 2, ID>(make_text(str, POS, 1), format_str);
  352. } else if constexpr (str[POS + 1] == '}' || str[POS + 1] == ':') {
  353. static_assert(ID != manual_indexing_id,
  354. "cannot switch from manual to automatic argument indexing");
  355. constexpr auto next_id =
  356. ID != manual_indexing_id ? ID + 1 : manual_indexing_id;
  357. return parse_replacement_field_then_tail<get_type<ID, Args>, Args,
  358. POS + 1, ID, next_id>(
  359. format_str);
  360. } else {
  361. constexpr auto arg_id_result =
  362. parse_arg_id<ID>(str.data() + POS + 1, str.data() + str.size());
  363. constexpr auto arg_id_end_pos = arg_id_result.arg_id_end - str.data();
  364. constexpr char_type c =
  365. arg_id_end_pos != str.size() ? str[arg_id_end_pos] : char_type();
  366. static_assert(c == '}' || c == ':', "missing '}' in format string");
  367. if constexpr (arg_id_result.arg_id.kind == arg_id_kind::index) {
  368. static_assert(
  369. ID == manual_indexing_id || ID == 0,
  370. "cannot switch from automatic to manual argument indexing");
  371. constexpr auto arg_index = arg_id_result.arg_id.val.index;
  372. return parse_replacement_field_then_tail<get_type<arg_index, Args>,
  373. Args, arg_id_end_pos,
  374. arg_index, manual_indexing_id>(
  375. format_str);
  376. } else if constexpr (arg_id_result.arg_id.kind == arg_id_kind::name) {
  377. constexpr auto arg_index =
  378. get_arg_index_by_name(arg_id_result.arg_id.val.name, Args{});
  379. if constexpr (arg_index != invalid_arg_index) {
  380. constexpr auto next_id =
  381. ID != manual_indexing_id ? ID + 1 : manual_indexing_id;
  382. return parse_replacement_field_then_tail<
  383. decltype(get_type<arg_index, Args>::value), Args, arg_id_end_pos,
  384. arg_index, next_id>(format_str);
  385. } else {
  386. if constexpr (c == '}') {
  387. return parse_tail<Args, arg_id_end_pos + 1, ID>(
  388. runtime_named_field<char_type>{arg_id_result.arg_id.val.name},
  389. format_str);
  390. } else if constexpr (c == ':') {
  391. return unknown_format(); // no type info for specs parsing
  392. }
  393. }
  394. }
  395. }
  396. } else if constexpr (str[POS] == '}') {
  397. if constexpr (POS + 1 == str.size())
  398. FMT_THROW(format_error("unmatched '}' in format string"));
  399. return parse_tail<Args, POS + 2, ID>(make_text(str, POS, 1), format_str);
  400. } else {
  401. constexpr auto end = parse_text(str, POS + 1);
  402. if constexpr (end - POS > 1) {
  403. return parse_tail<Args, end, ID>(make_text(str, POS, end - POS),
  404. format_str);
  405. } else {
  406. return parse_tail<Args, end, ID>(code_unit<char_type>{str[POS]},
  407. format_str);
  408. }
  409. }
  410. }
  411. template <typename... Args, typename S,
  412. FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
  413. constexpr auto compile(S format_str) {
  414. constexpr auto str = basic_string_view<typename S::char_type>(format_str);
  415. if constexpr (str.size() == 0) {
  416. return detail::make_text(str, 0, 0);
  417. } else {
  418. constexpr auto result =
  419. detail::compile_format_string<detail::type_list<Args...>, 0, 0>(
  420. format_str);
  421. return result;
  422. }
  423. }
  424. #endif // defined(__cpp_if_constexpr) && defined(__cpp_return_type_deduction)
  425. } // namespace detail
  426. FMT_BEGIN_EXPORT
  427. #if defined(__cpp_if_constexpr) && defined(__cpp_return_type_deduction)
  428. template <typename CompiledFormat, typename... Args,
  429. typename Char = typename CompiledFormat::char_type,
  430. FMT_ENABLE_IF(detail::is_compiled_format<CompiledFormat>::value)>
  431. FMT_INLINE std::basic_string<Char> format(const CompiledFormat& cf,
  432. const Args&... args) {
  433. auto s = std::basic_string<Char>();
  434. cf.format(std::back_inserter(s), args...);
  435. return s;
  436. }
  437. template <typename OutputIt, typename CompiledFormat, typename... Args,
  438. FMT_ENABLE_IF(detail::is_compiled_format<CompiledFormat>::value)>
  439. constexpr FMT_INLINE OutputIt format_to(OutputIt out, const CompiledFormat& cf,
  440. const Args&... args) {
  441. return cf.format(out, args...);
  442. }
  443. template <typename S, typename... Args,
  444. FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
  445. FMT_INLINE std::basic_string<typename S::char_type> format(const S&,
  446. Args&&... args) {
  447. if constexpr (std::is_same<typename S::char_type, char>::value) {
  448. constexpr auto str = basic_string_view<typename S::char_type>(S());
  449. if constexpr (str.size() == 2 && str[0] == '{' && str[1] == '}') {
  450. const auto& first = detail::first(args...);
  451. if constexpr (detail::is_named_arg<
  452. remove_cvref_t<decltype(first)>>::value) {
  453. return fmt::to_string(first.value);
  454. } else {
  455. return fmt::to_string(first);
  456. }
  457. }
  458. }
  459. constexpr auto compiled = detail::compile<Args...>(S());
  460. if constexpr (std::is_same<remove_cvref_t<decltype(compiled)>,
  461. detail::unknown_format>()) {
  462. return fmt::format(
  463. static_cast<basic_string_view<typename S::char_type>>(S()),
  464. std::forward<Args>(args)...);
  465. } else {
  466. return fmt::format(compiled, std::forward<Args>(args)...);
  467. }
  468. }
  469. template <typename OutputIt, typename S, typename... Args,
  470. FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
  471. FMT_CONSTEXPR OutputIt format_to(OutputIt out, const S&, Args&&... args) {
  472. constexpr auto compiled = detail::compile<Args...>(S());
  473. if constexpr (std::is_same<remove_cvref_t<decltype(compiled)>,
  474. detail::unknown_format>()) {
  475. return fmt::format_to(
  476. out, static_cast<basic_string_view<typename S::char_type>>(S()),
  477. std::forward<Args>(args)...);
  478. } else {
  479. return fmt::format_to(out, compiled, std::forward<Args>(args)...);
  480. }
  481. }
  482. #endif
  483. template <typename OutputIt, typename S, typename... Args,
  484. FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
  485. format_to_n_result<OutputIt> format_to_n(OutputIt out, size_t n,
  486. const S& format_str, Args&&... args) {
  487. auto it = fmt::format_to(detail::truncating_iterator<OutputIt>(out, n),
  488. format_str, std::forward<Args>(args)...);
  489. return {it.base(), it.count()};
  490. }
  491. template <typename S, typename... Args,
  492. FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
  493. FMT_CONSTEXPR20 size_t formatted_size(const S& format_str,
  494. const Args&... args) {
  495. return fmt::format_to(detail::counting_iterator(), format_str, args...)
  496. .count();
  497. }
  498. template <typename S, typename... Args,
  499. FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
  500. void print(std::FILE* f, const S& format_str, const Args&... args) {
  501. memory_buffer buffer;
  502. fmt::format_to(std::back_inserter(buffer), format_str, args...);
  503. detail::print(f, {buffer.data(), buffer.size()});
  504. }
  505. template <typename S, typename... Args,
  506. FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
  507. void print(const S& format_str, const Args&... args) {
  508. print(stdout, format_str, args...);
  509. }
  510. #if FMT_USE_NONTYPE_TEMPLATE_ARGS
  511. inline namespace literals {
  512. template <detail_exported::fixed_string Str> constexpr auto operator""_cf() {
  513. using char_t = remove_cvref_t<decltype(Str.data[0])>;
  514. return detail::udl_compiled_string<char_t, sizeof(Str.data) / sizeof(char_t),
  515. Str>();
  516. }
  517. } // namespace literals
  518. #endif
  519. FMT_END_EXPORT
  520. FMT_END_NAMESPACE
  521. #endif // FMT_COMPILE_H_