Boost C++ Libraries: Ticket #1976: Inverse function for complete https://svn.boost.org/trac10/ticket/1976 <p> As mentioned in the '[boost] [filesystem] "leaf"' thread, complete is the only path composition function without a corresponding decomposition function. </p> <p> The idea: uncomplete(/foo/new, /foo/bar) =&gt; ../new </p> <p> The use case for this is any time you get a full path (from an open dialog, perhaps) and want to store a relative path so that the group of files can be moved to a different directory without breaking the paths. An IDE would be a simple example, so that the project file could be safely checked out of subversion. </p> <p> I'd like to call it relative, but that conceptually conflicts with the relative_path member decomposition function. Perhaps the member function could be changed to local_path(), or something. </p> <p> A discussion will need to be held to determine expected behaviour in the presence of symlinks, since root/foo/bar/.. is not always root/foo. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/1976 Trac 1.4.3 me22.ca+boost@… Thu, 21 Aug 2008 23:52:35 GMT <link>https://svn.boost.org/trac10/ticket/1976#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1976#comment:1</guid> <description> <p> An additional use case for this came up on the users list: <a class="ext-link" href="http://lists.boost.org/boost-users/2008/08/39597.php"><span class="icon">​</span>http://lists.boost.org/boost-users/2008/08/39597.php</a> </p> <blockquote> <p> The use case here is creating complete output paths for "copy-pasting a sub-tree from input_base_path to output_base_path" (ofcourse with some transformations along the way). </p> </blockquote> <blockquote> <p> For now, I am using </p> </blockquote> <pre class="wiki"> fs::wpath output_path=output_base_path; int k=0; for(fs::wpath::iterator i=input_path.begin();i!=input_path.end();i++,k++) if(k&gt;=7) output_path/=(*i); </pre><blockquote> <p> Again, 7 is the number of elements in input_base_path. advance() would make it atleast slightly cleaner (remove k, and the if on k), uncomplete would be ideal. </p> </blockquote> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 22 Aug 2008 00:56:14 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1976#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1976#comment:2</guid> <description> <p> Here's a naive implementation (that doesn't handle symlinks and isn't well tested): </p> <pre class="wiki">#include &lt;boost/filesystem.hpp&gt; boost::filesystem::path naive_uncomplete(boost::filesystem::path const path, boost::filesystem::path const base) { if (path.has_root_path()){ if (path.root_path() != base.root_path()) { return path; } else { return naive_uncomplete(path.relative_path(), base.relative_path()); } } else { if (base.has_root_path()) { throw "cannot uncomplete a path relative path from a rooted base"; } else { typedef boost::filesystem::path::const_iterator path_iterator; path_iterator path_it = path.begin(); path_iterator base_it = base.begin(); while ( path_it != path.end() &amp;&amp; base_it != base.end() ) { if (*path_it != *base_it) break; ++path_it; ++base_it; } boost::filesystem::path result; for (; base_it != base.end(); ++base_it) { result /= ".."; } for (; path_it != path.end(); ++path_it) { result /= *path_it; } return result; } } } </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Sat, 07 Feb 2009 02:58:40 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1976#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1976#comment:3</guid> <description> <p> I would like this functionality to be added as well. My use case is similar to the first one mentioned (wanting to persist relative paths). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Sat, 21 Feb 2009 11:54:28 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1976#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1976#comment:4</guid> <description> <p> Getting paths relative to an arbitrary directory is a very useful feature. My use case is the same at the first one (it is an IDE which needs to store paths relative to project file). </p> </description> <category>Ticket</category> </item> <item> <author>tom@…</author> <pubDate>Mon, 06 Jul 2009 12:29:50 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1976#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1976#comment:5</guid> <description> <p> I would like this for a media application which should save lines in an M3U playlist as filepaths relative to the playlist path. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 13 Jul 2010 19:24:40 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1976#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1976#comment:6</guid> <description> <p> This would be useful for me as well. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 11 Mar 2011 10:07:46 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1976#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1976#comment:7</guid> <description> <p> This feature would be very useful for us, too. In a use case similar to the first one. </p> </description> <category>Ticket</category> </item> <item> <author>sorokin@…</author> <pubDate>Sun, 24 Apr 2011 20:08:57 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1976#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1976#comment:8</guid> <description> <p> Is there any plans to include this function is boost? Maybe under name relativize? </p> </description> <category>Ticket</category> </item> <item> <author>Taylor Braun-Jones <taylor@…></author> <pubDate>Thu, 08 Dec 2011 15:17:51 GMT</pubDate> <title>cc set https://svn.boost.org/trac10/ticket/1976#comment:9 https://svn.boost.org/trac10/ticket/1976#comment:9 <ul> <li><strong>cc</strong> <span class="trac-author">taylor@…</span> added </li> </ul> Ticket anonymous Thu, 08 Nov 2012 08:07:11 GMT <link>https://svn.boost.org/trac10/ticket/1976#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1976#comment:10</guid> <description> <p> I'm interested in this feature too. </p> </description> <category>Ticket</category> </item> <item> <author>Chris Pick <boost@…></author> <pubDate>Sun, 10 Feb 2013 02:46:50 GMT</pubDate> <title>cc changed https://svn.boost.org/trac10/ticket/1976#comment:11 https://svn.boost.org/trac10/ticket/1976#comment:11 <ul> <li><strong>cc</strong> <span class="trac-author">boost@…</span> added </li> </ul> Ticket anonymous Mon, 27 Jan 2014 22:12:53 GMT <link>https://svn.boost.org/trac10/ticket/1976#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1976#comment:12</guid> <description> <p> There a quite a few links on the internet linking here. This would be a great feature. I'd wonder how to make this portable though with drive letters on windows, reparse points, symlinks on *nix... </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 05 Mar 2014 16:47:33 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1976#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1976#comment:13</guid> <description> <p> There's an example at <a class="ext-link" href="https://svn.boost.org/trac/boost/ticket/6249"><span class="icon">​</span>https://svn.boost.org/trac/boost/ticket/6249</a> , it relies only on lexicographic compare so doesn't handle links etc, but on the other hand I think the expected behavior of such a function is that it's entirely lexicographic on the path. </p> </description> <category>Ticket</category> </item> <item> <author>slowriot <riot@…></author> <pubDate>Sat, 15 Nov 2014 15:56:56 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1976#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1976#comment:14</guid> <description> <p> +1 for this as well </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 29 Jul 2015 00:29:20 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1976#comment:15 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1976#comment:15</guid> <description> <p> I also need this! </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Beman Dawes</dc:creator> <pubDate>Sat, 05 Sep 2015 18:22:25 GMT</pubDate> <title>status, milestone changed; resolution set https://svn.boost.org/trac10/ticket/1976#comment:16 https://svn.boost.org/trac10/ticket/1976#comment:16 <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> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.36.0</span> → <span class="trac-field-new">Boost 1.60.0</span> </li> </ul> <p> Boost 1.60.0 will add functions lexically_normal, lexically_relative, relative, and weakly_canonical. These are designed to provide the functionality requested by this ticket. </p> <p> See <a class="ext-link" href="http://boostorg.github.io/filesystem/relative_proposal.html"><span class="icon">​</span>http://boostorg.github.io/filesystem/relative_proposal.html</a> for more information. It proposes additional lexical and operational proximate functions, but I have chosen not to include those now. They will be reconsidered once users get some field experience with the core functionality for computing relative paths. </p> <p> These function are available now on the <a class="ext-link" href="https://github.com/boostorg/filesystem"><span class="icon">​</span>https://github.com/boostorg/filesystem</a> develop branch, and will be merged to master as soon as sufficient regression tests have cycled. They will also be proposed for inclusion in the next version of the C++ committee's TS 18822, File System Technical Specification. </p> <p> Many thanks to Jamie Allsop for his help and perseverance, and to everyone else who made suggestions and comments. Jamie's paper is available at <a class="ext-link" href="https://github.com/ja11sop/std-filesystem-relative"><span class="icon">​</span>https://github.com/ja11sop/std-filesystem-relative</a> </p> <p> Thanks, </p> <p> --Beman </p> Ticket