mirror of
https://github.com/boostorg/filesystem.git
synced 2026-01-19 04:12:09 +00:00
Use explicit operator+= and operator/= overloads for path and string types.
This is necessary to allow to pass arguments convertible to path and compatible string types to these operators. Fixes https://github.com/boostorg/filesystem/issues/223.
This commit is contained in:
@@ -39,6 +39,11 @@
|
||||
</td>
|
||||
</table>
|
||||
|
||||
<h2>1.79.0</h2>
|
||||
<ul>
|
||||
<li>Fixed compilation of path appending and concatenation operators with arguments of types convertible to <code>path</code> or compatible string type. (<a href="https://github.com/boostorg/filesystem/issues/223">#223</a>)</li>
|
||||
</ul>
|
||||
|
||||
<h2>1.78.0</h2>
|
||||
<ul>
|
||||
<li><b>v4:</b> <code>path::filename</code> and <code>path::iterator</code> no longer return an implicit trailing dot (".") element if the path ends with a directory separator. Instead, an empty path is returned, similar to C++17 std::filesystem. This also affects other methods that are defined in terms of iterators or filename, such as <code>path::stem</code>, <code>path::compare</code> or <code>lexicographical_compare</code>. For example, <code>path("a/b/") == path("a/b/.")</code> no longer holds true. (<a href="https://github.com/boostorg/filesystem/issues/193">#193</a>)</li>
|
||||
|
||||
@@ -430,9 +430,24 @@ public:
|
||||
|
||||
// ----- concatenation -----
|
||||
|
||||
path& operator+=(path const& p)
|
||||
{
|
||||
return concat(p);
|
||||
}
|
||||
|
||||
path& operator+=(const value_type* ptr)
|
||||
{
|
||||
return concat(ptr);
|
||||
}
|
||||
|
||||
path& operator+=(string_type const& s)
|
||||
{
|
||||
return concat(s);
|
||||
}
|
||||
|
||||
template< class Source >
|
||||
typename boost::enable_if_c<
|
||||
path_traits::is_pathable< typename boost::decay< Source >::type >::value || path_detail::is_native_pathable< Source >::value,
|
||||
path_traits::is_pathable< typename boost::decay< Source >::type >::value && !path_detail::is_native_pathable< Source >::value,
|
||||
path&
|
||||
>::type operator+=(Source const& source)
|
||||
{
|
||||
@@ -552,9 +567,24 @@ public:
|
||||
// if a separator is added, it is the preferred separator for the platform;
|
||||
// slash for POSIX, backslash for Windows
|
||||
|
||||
path& operator/=(path const& p)
|
||||
{
|
||||
return append(p);
|
||||
}
|
||||
|
||||
path& operator/=(const value_type* ptr)
|
||||
{
|
||||
return append(ptr);
|
||||
}
|
||||
|
||||
path& operator/=(string_type const& s)
|
||||
{
|
||||
return append(s);
|
||||
}
|
||||
|
||||
template< class Source >
|
||||
BOOST_FORCEINLINE typename boost::enable_if_c<
|
||||
path_traits::is_pathable< typename boost::decay< Source >::type >::value || path_detail::is_native_pathable< Source >::value,
|
||||
path_traits::is_pathable< typename boost::decay< Source >::type >::value && !path_detail::is_native_pathable< Source >::value,
|
||||
path&
|
||||
>::type operator/=(Source const& source)
|
||||
{
|
||||
|
||||
@@ -82,6 +82,56 @@ using boost::prior;
|
||||
#define PATH_TEST_EQ(a, b) check(a, b, __FILE__, __LINE__)
|
||||
|
||||
namespace {
|
||||
|
||||
class derived_from_path :
|
||||
public fs::path
|
||||
{
|
||||
public:
|
||||
derived_from_path() {}
|
||||
derived_from_path(derived_from_path const& that) : fs::path(static_cast< fs::path const& >(that)) {}
|
||||
template< typename T >
|
||||
derived_from_path(T const& that) : fs::path(that) {}
|
||||
|
||||
derived_from_path& operator= (derived_from_path const& that)
|
||||
{
|
||||
*static_cast< fs::path* >(this) = that;
|
||||
return *this;
|
||||
}
|
||||
template< typename T >
|
||||
derived_from_path& operator= (T const& that)
|
||||
{
|
||||
*static_cast< fs::path* >(this) = that;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
class convertible_to_path
|
||||
{
|
||||
private:
|
||||
fs::path m_path;
|
||||
|
||||
public:
|
||||
convertible_to_path() {}
|
||||
convertible_to_path(convertible_to_path const& that) : m_path(that.m_path) {}
|
||||
template< typename T >
|
||||
convertible_to_path(T const& that) : m_path(that) {}
|
||||
|
||||
convertible_to_path& operator= (convertible_to_path const& that)
|
||||
{
|
||||
m_path = that.m_path;
|
||||
return *this;
|
||||
}
|
||||
template< typename T >
|
||||
convertible_to_path& operator= (T const& that)
|
||||
{
|
||||
m_path = that;
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator fs::path() const { return m_path; }
|
||||
};
|
||||
|
||||
|
||||
std::string platform(BOOST_PLATFORM);
|
||||
|
||||
void check(const fs::path& source, const std::string& expected, const char* file, int line)
|
||||
@@ -2004,8 +2054,14 @@ void construction_tests()
|
||||
p1 /= appnd;\
|
||||
PATH_TEST_EQ(p1, expected);\
|
||||
path p2(p);\
|
||||
p2.append(s.begin(), s.end());\
|
||||
PATH_TEST_EQ(p2.string(), expected);\
|
||||
p2 /= derived_from_path(appnd);\
|
||||
PATH_TEST_EQ(p2, expected);\
|
||||
path p3(p);\
|
||||
p3 /= convertible_to_path(appnd);\
|
||||
PATH_TEST_EQ(p3, expected);\
|
||||
path p4(p);\
|
||||
p4.append(s.begin(), s.end());\
|
||||
PATH_TEST_EQ(p4.string(), expected);\
|
||||
}
|
||||
|
||||
void append_tests()
|
||||
@@ -2133,8 +2189,14 @@ void append_tests()
|
||||
p4 += s.c_str();\
|
||||
PATH_TEST_EQ(p4.string(), expected);\
|
||||
path p5(p);\
|
||||
p5.concat(s.begin(), s.end());\
|
||||
PATH_TEST_EQ(p5.string(), expected);\
|
||||
p5 += derived_from_path(appnd);\
|
||||
PATH_TEST_EQ(p5, expected);\
|
||||
path p6(p);\
|
||||
p6 += convertible_to_path(appnd);\
|
||||
PATH_TEST_EQ(p6, expected);\
|
||||
path p7(p);\
|
||||
p7.concat(s.begin(), s.end());\
|
||||
PATH_TEST_EQ(p7.string(), expected);\
|
||||
}
|
||||
|
||||
void concat_tests()
|
||||
|
||||
Reference in New Issue
Block a user