Ookii.CommandLine for C++  2.0.0
format_helper.h
Go to the documentation of this file.
1 #ifndef OOKII_FORMAT_HELPER_H_
12 #define OOKII_FORMAT_HELPER_H_
13 
14 #include "string_helper.h"
15 
16 #if __has_include(<format>) && !defined(OOKII_FORCE_LIBFMT)
17 
18 #include <format>
19 
23 #define OOKII_FMT_NS std::
24 
25 #else
26 
27 #include <fmt/core.h>
28 #include <fmt/ranges.h>
29 #include <fmt/xchar.h>
30 
34 #define OOKII_FMT_NS fmt::
35 
39 #define OOKII_USING_LIBFMT
40 
41 #endif
42 
44 namespace ookii::format
45 {
54  template<typename... Args>
55  std::string ncformat(const std::locale &loc, std::string_view format, Args&&... args)
56  {
57  return OOKII_FMT_NS vformat(loc, format, OOKII_FMT_NS make_format_args(std::forward<Args>(args)...));
58  }
59 
68  template<typename... Args>
69  std::wstring ncformat(const std::locale &loc, std::wstring_view format, Args&&... args)
70  {
71  return OOKII_FMT_NS vformat(loc, format, OOKII_FMT_NS make_format_args<OOKII_FMT_NS wformat_context>(std::forward<Args>(args)...));
72  }
73 }
74 
75 #endif
#define OOKII_FMT_NS
The namespace which contains the formatting library.
Definition: format_helper.h:34
Namespace containing helper functions for formatting.
Definition: format_helper.h:45
std::string ncformat(const std::locale &loc, std::string_view format, Args &&... args)
Helper to format using a non-const format string without needing to explicitly construct a format_arg...
Definition: format_helper.h:55
Provides helper types and functions for working with strings.