Boost C++ Libraries: Ticket #1936: Make basic_path more generic? https://svn.boost.org/trac10/ticket/1936 <p> in several places I need to have code which works both with char and wchar_t. Those are template functions. I also work with paths there so I wanted to actually write something like </p> <p> template &lt;typename <a class="missing wiki">CharType</a>&gt; void foo(const std::basic_string&lt;<a class="missing wiki">CharType</a>&gt;&amp; s) { </p> <blockquote> <p> typedef fs::basic_path&lt;std::basic_string&lt;CharType&gt; &gt; path_type; ... </p> </blockquote> <p> } </p> <p> but it turned out that I can't do it because 1) basic_path has the second Traits template parameter mandatory and 2) this Traits parameter has actually different type for path and wpath: </p> <blockquote> <p> struct path_traits; typedef basic_path&lt; std::string, path_traits &gt; path; <em> ... struct BOOST_FILESYSTEM_DECL wpath_traits; typedef basic_path&lt; std::wstring, wpath_traits &gt; wpath; </em></p> </blockquote> <p> Of course, I can easily workaround it with my own traits, but I wonder could it be in the first place like: </p> <blockquote> <p> template&lt;class String&gt; class basic_path_traits; </p> </blockquote> <blockquote> <p> template&lt;class String, class Traits = basic_path_traits&lt;String&gt; &gt; class basic_path; </p> </blockquote> <p> with basic_path_traits being specialized for std::string and std::wstring and fs::path and fs::wpath being just </p> <blockquote> <p> typedef basic_path&lt; std::string &gt; path; typedef basic_path&lt; std::wstring &gt; wpath; </p> </blockquote> <p> ? </p> <p> Thanks. </p> <p> -- Alexei Alexandrov </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/1936 Trac 1.4.3 Beman Dawes Tue, 20 May 2008 13:12:42 GMT status changed https://svn.boost.org/trac10/ticket/1936#comment:1 https://svn.boost.org/trac10/ticket/1936#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> There are two perspectives to consider at this issue. </p> <ul><li>As a very specific tweak to the current interface. </li></ul><ul><li>As a further indication that there should be a single path type that can handle both wide and narrow types. Peter Dimov suggested that once, and I keep turning over in my mind how it could be accomplished. With C++0x supplying two new character types, the need becomes more pressing. I still don't want to invent a solution that applies only to filesystem paths; there is a general need for strings that can cope with multiple character types and encodings. </li></ul><p> --Beman </p> Ticket Beman Dawes Tue, 20 May 2008 13:18:26 GMT component changed https://svn.boost.org/trac10/ticket/1936#comment:2 https://svn.boost.org/trac10/ticket/1936#comment:2 <ul> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">filesystem</span> </li> </ul> Ticket Beman Dawes Wed, 25 Jun 2008 21:34:48 GMT status changed https://svn.boost.org/trac10/ticket/1936#comment:3 https://svn.boost.org/trac10/ticket/1936#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">new</span> </li> </ul> Ticket anonymous Sun, 02 Nov 2008 00:01:45 GMT <link>https://svn.boost.org/trac10/ticket/1936#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1936#comment:4</guid> <description> <blockquote class="citation"> <ul><li>As a further indication that there should be a single path type that can handle both wide and narrow types. Peter Dimov suggested that once, and I keep turning over in my mind how it could be accomplished. With C++0x supplying two new character types, the need becomes more pressing. I still don't want to invent a solution that applies only to filesystem paths; there is a general need for strings that can cope with multiple character types and encodings. </li></ul></blockquote> <p> This is indeed a very big problem and needs to be addressed properly, quickly. It is for this reason that I can't use boost::filesystem and have had to revert to using QT's QFile and friends. Their QString has loads of support for encodings and QFile uses QString. I had hoped C++0x would take us a lot closer to better i18n support. </p> </description> <category>Ticket</category> </item> <item> <author>dtrebbien@…</author> <pubDate>Sat, 30 Jan 2010 04:05:05 GMT</pubDate> <title>severity, milestone changed; cc set https://svn.boost.org/trac10/ticket/1936#comment:5 https://svn.boost.org/trac10/ticket/1936#comment:5 <ul> <li><strong>cc</strong> <span class="trac-author">dtrebbien@…</span> added </li> <li><strong>severity</strong> <span class="trac-field-old">Not Applicable</span> → <span class="trac-field-new">Problem</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.36.0</span> → <span class="trac-field-new">To Be Determined</span> </li> </ul> <p> Does anyone know what the status of this feature request is? Is anyone working on it? I have run into a situation where I need something like a <code>basic_path_traits</code> template in order to <em>not</em> have to copy a huge template definition just to create specializations for <code>char</code> and <code>wchar_t</code>. </p> <p> Beman, I read your <a class="ext-link" href="http://lists.boost.org/Archives/boost/2008/05/137616.php"><span class="icon">​</span>message in the Boost mailing list</a> and I do not see why you are talking about character encodings. Granted, I have not looked into the code of Boost Filesystem and I am not familiar with its internal workings, but would you mind elaborating on the issue involved here? </p> Ticket dtrebbien@… Sat, 30 Jan 2010 17:56:23 GMT <link>https://svn.boost.org/trac10/ticket/1936#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1936#comment:6</guid> <description> <p> I developed a partial work-around for those who, like me, are only interested in a "<code>basic_path_traits</code> template" for (<code>char</code>, <code>std::char_traits&lt;char&gt;</code>) and (<code>wchar_t</code>, <code>std::char_traits&lt;wchar_t&gt;</code>): </p> <div class="wiki-code"><div class="code"><pre><span class="k">namespace</span> <span class="n">detail</span> <span class="p">{</span> <span class="k">template</span> <span class="o">&lt;</span><span class="k">typename</span> <span class="n">char_t_</span><span class="p">,</span> <span class="k">class</span> <span class="nc">traits_</span> <span class="o">=</span> <span class="n">std</span><span class="o">::</span><span class="n">char_traits</span><span class="o">&lt;</span><span class="n">char_t_</span><span class="o">&gt;</span> <span class="o">&gt;</span> <span class="k">struct</span> <span class="n">boost_ticket_1936_workaround</span><span class="p">;</span> <span class="k">template</span> <span class="o">&lt;&gt;</span> <span class="k">struct</span> <span class="n">boost_ticket_1936_workaround</span><span class="o">&lt;</span><span class="kt">char</span><span class="o">&gt;</span> <span class="p">{</span> <span class="k">typedef</span> <span class="n">boost</span><span class="o">::</span><span class="n">filesystem</span><span class="o">::</span><span class="n">path_traits</span> <span class="n">boost_filesystem_path_traits</span><span class="p">;</span> <span class="p">};</span> <span class="k">template</span> <span class="o">&lt;&gt;</span> <span class="k">struct</span> <span class="n">boost_ticket_1936_workaround</span><span class="o">&lt;</span><span class="kt">wchar_t</span><span class="o">&gt;</span> <span class="p">{</span> <span class="k">typedef</span> <span class="n">boost</span><span class="o">::</span><span class="n">filesystem</span><span class="o">::</span><span class="n">wpath_traits</span> <span class="n">boost_filesystem_path_traits</span><span class="p">;</span> <span class="p">};</span> <span class="p">}</span> <span class="c1">// end `namespace detail`</span> </pre></div></div><p> Using this code, the generic path traits type is <code>BOOST_DEDUCED_TYPENAME detail::boost_ticket_1936_workaround&lt;char_t_, traits_&gt;::boost_filesystem_path_traits</code> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Beman Dawes</dc:creator> <pubDate>Fri, 11 Jun 2010 15:57:02 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/1936#comment:7 https://svn.boost.org/trac10/ticket/1936#comment:7 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Boost.Filesystem Version 3, which will ship with Boost 1.44, address the issues raised by this ticket. </p> <p> Thanks, </p> <p> --Beman </p> Ticket