title: How to write a formatter for fmt using wchar_t?
body: <p>I want to specialize a formatter template so I can write:</p>
  
  <pre><code>rect    rc(0, 0, 100, 20);
  wstring buf = fmt_msg(L"{0}", rc);
  </code></pre>
  
  <p>I have this: </p>
  
  <pre><code>ea::wstring
  vfmt_msg(const ea::wstring &amp;msg, fmt::wformat_args args) {
    std::wstring s_ = fmt::vformat(std::wstring(msg.data()), args);
    return ea::wstring(s_.data());
  }
  
  template &lt;typename... TArgs&gt;
  wstring
  fmt_msg(wstring cc &amp;format, TArgs cc &amp;... args) {
    return vfmt_msg(format, fmt::make_format_args&lt;fmt::wformat_context&gt;(args...));
  }
  
  namespace fmt {
  template &lt;&gt; struct formatter&lt;rect&gt; {
    template &lt;typename ParseContext&gt; constexpr auto parse(ParseContext &amp;ctx) {
      return ctx.begin();
    }
    template &lt;typename FormatContext&gt;
    auto format(const rect &amp;rc, FormatContext &amp;ctx) {
      return format_to(ctx.begin(), L"{{({}, {}, {}, {}), cx: {}, cy: {}}}", rc.x,
                       rc.y, rc.x2, rc.y2, rc.cx(), rc.cy());
    }
  };
  } // namespace fmt
  </code></pre>
  
  <p>But I get this: </p>
  
  <pre class="lang-none prettyprint-override"><code>fmt\core.h(844,1): error C2664:  'const void *fmt::v5::internal::arg_mapper&lt;Context&gt;::map(std::nullptr_t)': cannot convert argument 1 from 'Arg' to 'signed char'
  fmt\core.h(844,1): error C2664:         with
  fmt\core.h(844,1): error C2664:         [
  fmt\core.h(844,1): error C2664:             Context=fmt::v5::basic_format_context&lt;std::back_insert_iterator&lt;fmt::v5::internal::buffer&lt;wchar_t&gt;&gt;,wchar_t&gt;
  fmt\core.h(844,1): error C2664:         ]
  fmt\core.h(844,1): error C2664:         and
  fmt\core.h(844,1): error C2664:         [
  fmt\core.h(844,1): error C2664:             Arg=rect
  fmt\core.h(844,1): error C2664:         ] (compiling source file trace.cpp)
  fmt\core.h(844,69): message :  No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called (compiling source file trace.cpp)
  fmt\core.h(1000): message :  see reference to alias template instantiation 'fmt::v5::internal::mapped_type_constant&lt;rect,fmt::v5::basic_format_context&lt;std::back_insert_iterator&lt;fmt::v5::internal::buffer&lt;wchar_t&gt;&gt;,wchar_t&gt;&gt;' being compiled (compiling source file trace.cpp)
  fmt\core.h(1102): message :  see reference to function template instantiation 'unsigned __int64 fmt::v5::internal::encode_types&lt;Context,rect,&gt;(void)' being compiled
  fmt\core.h(1102): message :         with
  fmt\core.h(1102): message :         [
  fmt\core.h(1102): message :             Context=fmt::v5::basic_format_context&lt;std::back_insert_iterator&lt;fmt::v5::internal::buffer&lt;wchar_t&gt;&gt;,wchar_t&gt;
  fmt\core.h(1102): message :         ] (compiling source file trace.cpp)
  core\typedefs.h(124): message :  see reference to class template instantiation 'fmt::v5::format_arg_store&lt;fmt::v5::basic_format_context&lt;std::back_insert_iterator&lt;fmt::v5::internal::buffer&lt;wchar_t&gt;&gt;,wchar_t&gt;,rect&gt;' being compiled (compiling source file trace.cpp)
  core\trace.cpp(73): message :  see reference to function template instantiation 'wstring fmt_msg&lt;rect&gt;(const wstring &amp;,const rect &amp;)' being compiled
  </code></pre>
  
  <p>But it works if I do this on char and so I tried:</p>
  
  <pre><code>namespace fmt {
  template &lt;&gt; struct formatter&lt;rect, wchar_t&gt; {
    template &lt;typename ParseContext&gt; constexpr auto parse(ParseContext &amp;ctx) {
      return ctx.begin();
    }
    template &lt;typename FormatContext&gt;
    auto format(const rect &amp;rc, FormatContext &amp;ctx) {
      return format_to(ctx.begin(), "{{({}, {}, {}, {}), cx: {}, cy: {}}}", rc.x,
                       rc.y, rc.x2, rc.y2, rc.cx(), rc.cy());
    }
  };
  } // namespace fmt
  </code></pre>
  
  <p>note the template &lt;> struct formatter &lt; rect, <strong>wchar_t</strong> > part</p>
  
  <p>But I get:</p>
  
  <pre class="lang-none prettyprint-override"><code>core\trace.cpp(55,1): error C2039:  'begin': is not a member of 'fmt::v5::basic_format_context&lt;std::back_insert_iterator&lt;fmt::v5::internal::buffer&lt;wchar_t&gt;&gt;,wchar_t&gt;'
  fmt\core.h(1074): message :  see declaration of 'fmt::v5::basic_format_context&lt;std::back_insert_iterator&lt;fmt::v5::internal::buffer&lt;wchar_t&gt;&gt;,wchar_t&gt;'
  fmt\core.h(740): message :  see reference to function template instantiation 'auto fmt::v5::formatter&lt;rect,wchar_t,void&gt;::format&lt;Context&gt;(const rect &amp;,FormatContext &amp;)' being compiled
  fmt\core.h(740): message :         with
  fmt\core.h(740): message :         [
  fmt\core.h(740): message :             Context=fmt::v5::wformat_context,
  fmt\core.h(740): message :             FormatContext=fmt::v5::wformat_context
  fmt\core.h(740): message :         ] (compiling source file trace.cpp)
  fmt\core.h(727): message :  see reference to function template instantiation 'void fmt::v5::internal::value&lt;Context&gt;::format_custom_arg&lt;T,fmt::v5::formatter&lt;rect,wchar_t,void&gt;&gt;(const void *,fmt::v5::basic_parse_context&lt;wchar_t,fmt::v5::internal::error_handler&gt; &amp;,Context &amp;)' being compiled
  fmt\core.h(727): message :         with
  fmt\core.h(727): message :         [
  fmt\core.h(727): message :             Context=fmt::v5::wformat_context,
  fmt\core.h(727): message :             T=rect
  fmt\core.h(727): message :         ] (compiling source file trace.cpp)
  fmt\core.h(724): message :  see reference to function template instantiation 'void fmt::v5::internal::value&lt;Context&gt;::format_custom_arg&lt;T,fmt::v5::formatter&lt;rect,wchar_t,void&gt;&gt;(const void *,fmt::v5::basic_parse_context&lt;wchar_t,fmt::v5::internal::error_handler&gt; &amp;,Context &amp;)' being compiled
  fmt\core.h(724): message :         with
  fmt\core.h(724): message :         [
  fmt\core.h(724): message :             Context=fmt::v5::wformat_context,
  fmt\core.h(724): message :             T=rect
  fmt\core.h(724): message :         ] (compiling source file trace.cpp)
  fmt\core.h(1015): message :  see reference to function template instantiation 'fmt::v5::internal::value&lt;Context&gt;::value&lt;T&gt;(const T &amp;)' being compiled
  fmt\core.h(1015): message :         with
  fmt\core.h(1015): message :         [
  fmt\core.h(1015): message :             Context=fmt::v5::wformat_context,
  fmt\core.h(1015): message :             T=rect
  fmt\core.h(1015): message :         ] (compiling source file trace.cpp)
  fmt\core.h(1015): message :  see reference to function template instantiation 'fmt::v5::internal::value&lt;Context&gt;::value&lt;T&gt;(const T &amp;)' being compiled
  fmt\core.h(1015): message :         with
  fmt\core.h(1015): message :         [
  fmt\core.h(1015): message :             Context=fmt::v5::wformat_context,
  fmt\core.h(1015): message :             T=rect
  fmt\core.h(1015): message :         ] (compiling source file trace.cpp)
  fmt\core.h(1105): message :  see reference to function template instantiation 'fmt::v5::internal::value&lt;Context&gt; fmt::v5::internal::make_arg&lt;true,Context,rect,0&gt;(const T &amp;)' being compiled
  fmt\core.h(1105): message :         with
  fmt\core.h(1105): message :         [
  fmt\core.h(1105): message :             Context=fmt::v5::wformat_context,
  fmt\core.h(1105): message :             T=rect
  fmt\core.h(1105): message :         ] (compiling source file trace.cpp)
  fmt\core.h(1105): message :  while compiling class template member function 'fmt::v5::format_arg_store&lt;fmt::v5::basic_format_context&lt;std::back_insert_iterator&lt;fmt::v5::internal::buffer&lt;wchar_t&gt;&gt;,wchar_t&gt;,rect&gt;::format_arg_store(const rect &amp;)' (compiling source file trace.cpp)
  fmt\core.h(1120): message :  see reference to function template instantiation 'fmt::v5::format_arg_store&lt;fmt::v5::basic_format_context&lt;std::back_insert_iterator&lt;fmt::v5::internal::buffer&lt;wchar_t&gt;&gt;,wchar_t&gt;,rect&gt;::format_arg_store(const rect &amp;)' being compiled (compiling source file trace.cpp)
  core\typedefs.h(125): message :  see reference to class template instantiation 'fmt::v5::format_arg_store&lt;fmt::v5::basic_format_context&lt;std::back_insert_iterator&lt;fmt::v5::internal::buffer&lt;wchar_t&gt;&gt;,wchar_t&gt;,rect&gt;' being compiled (compiling source file trace.cpp)
  core\trace.cpp(73): message :  see reference to function template instantiation 'wstring fmt_msg&lt;rect&gt;(const wstring &amp;,const rect &amp;)' being compiled
  </code></pre>