Skip to content

Commit

Permalink
Add move constructor, move assignment, where called for in Filesystem…
Browse files Browse the repository at this point in the history
… TS.
  • Loading branch information
Beman committed Sep 7, 2015
1 parent 353851e commit 9d5415d
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 16 deletions.
11 changes: 6 additions & 5 deletions doc/release_history.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,18 @@ <h2>1.60.0</h2>
lexically_relative</a></code>, <code><a href="reference.html#op-relative">
relative</a></code>, and <code><a href="reference.html#weakly_canonical">
weakly_canonical</a></code>. Many thanks to Jamie Allsop for his help and
perseverance. Closes tickets
perseverance. Resoves tickets
<a href="https://svn.boost.org/trac/boost/ticket/1976">#1976</a>,
<a href="https://svn.boost.org/trac/boost/ticket/5897">#5897</a>,
<a href="https://svn.boost.org/trac/boost/ticket/6249">#6249</a></li>
<li><b>New:</b> Class <code>path</code> now has
<a href="reference.html#path-iterators"> <code>reverse_iterator</code>,
<code>const_reverse_iterator</code>, <code>rbegin()</code>, and <code>rend()</code></a>. </li>
<li><b>New:</b> C++11 <code>noexcept</code> used where applicable if supported
by the compiler.</li>
<li><b>New:</b> C++11 move constructors and move assignments used as specified
in the Filesystem TS if supported by the compiler.</li>
<li><b>New:</b> C++11 <code>noexcept</code> supplied as specified in the
Filesystem TS if supported by the compiler.</li>
<li><b>New:</b> C++11 move constructors and move assignments supplied as
specified in the Filesystem TS if supported by the compiler. Resolves
<a href="https://svn.boost.org/trac/boost/ticket/10291">#10291</a>.</li>
<li><b>New:</b> Existing functions whose names changed in the Filesystem TS
are now supported under both the old and new names.</li>
<li>Fix a race condition in <code>unique_path</code> by applying
Expand Down
9 changes: 8 additions & 1 deletion include/boost/filesystem/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@

#include <boost/config.hpp>
#include <boost/system/api_config.hpp> // for BOOST_POSIX_API or BOOST_WINDOWS_API
#include <boost/detail/workaround.hpp>
#include <boost/detail/workaround.hpp>

// BOOST_FILESYSTEM_NO_CXX11_DEFAULTED_RVALUE_REFS -----------------------------------//

# if defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) \
|| (defined(_MSC_VER) && _MSC_VER==1800) // =default fails for msvc 14.0 rvalue refs
# define BOOST_FILESYSTEM_NO_CXX11_DEFAULTED_RVALUE_REFS
# endif

// BOOST_FILESYSTEM_DEPRECATED needed for source compiles -----------------------------//

Expand Down
59 changes: 55 additions & 4 deletions include/boost/filesystem/operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,35 @@ namespace boost
class BOOST_FILESYSTEM_DECL file_status
{
public:
file_status() : m_value(status_error), m_perms(perms_not_known) {}
file_status() BOOST_NOEXCEPT : m_value(status_error), m_perms(perms_not_known) {}
explicit file_status(file_type v, perms prms = perms_not_known) BOOST_NOEXCEPT
: m_value(v), m_perms(prms) {}

# ifndef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
file_status(const file_status&) BOOST_NOEXCEPT = default;
file_status& operator=(const file_status&) BOOST_NOEXCEPT = default;
# endif

# if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
# if !defined(BOOST_FILESYSTEM_NO_CXX11_DEFAULTED_RVALUE_REFS)
file_status(file_status&&) BOOST_NOEXCEPT = default;
file_status& operator=(file_status&&) BOOST_NOEXCEPT = default;
# else
file_status(file_status&& rhs) BOOST_NOEXCEPT
{
m_value = std::move(rhs.m_value);
m_perms = std::move(rhs.m_perms);
}
file_status& operator=(file_status&& rhs) BOOST_NOEXCEPT
{
m_value = std::move(rhs.m_value);
m_perms = std::move(rhs.m_perms);
return *this;
}
# endif
# endif


// observers
file_type type() const BOOST_NOEXCEPT { return m_value; }
perms permissions() const BOOST_NOEXCEPT { return m_perms; }
Expand Down Expand Up @@ -340,9 +365,8 @@ namespace boost
BOOST_FILESYSTEM_DECL
void copy_directory(const path& from, const path& to, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
void copy_file(const path& from, const path& to,
BOOST_SCOPED_ENUM(copy_option) option, // See ticket #2925
system::error_code* ec=0);
void copy_file(const path& from, const path& to, // See ticket #2925
detail::copy_option option, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
void copy_symlink(const path& existing_symlink, const path& new_symlink, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
Expand Down Expand Up @@ -728,6 +752,33 @@ class BOOST_FILESYSTEM_DECL directory_entry
: m_path(p), m_status(st), m_symlink_status(symlink_st)
{}

#ifndef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
directory_entry(const directory_entry&) = default;
directory_entry& operator=(const directory_entry&) = default;
#endif


# if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
# if !defined(BOOST_FILESYSTEM_NO_CXX11_DEFAULTED_RVALUE_REFS)
directory_entry(directory_entry&&) BOOST_NOEXCEPT = default;
directory_entry& operator=(directory_entry&&) BOOST_NOEXCEPT = default;
# else
directory_entry(directory_entry&& rhs) BOOST_NOEXCEPT
{
m_path = std::move(rhs.m_path);
m_status = std::move(rhs.m_status);
m_symlink_status = std::move(rhs.m_symlink_status);
}
directory_entry& operator=(directory_entry&& rhs) BOOST_NOEXCEPT
{
m_path = std::move(rhs.m_path);
m_status = std::move(rhs.m_status);
m_symlink_status = std::move(rhs.m_symlink_status);
return *this;
}
# endif
# endif

void assign(const boost::filesystem::path& p,
file_status st = file_status(), file_status symlink_st = file_status())
{ m_path = p; m_status = st; m_symlink_status = symlink_st; }
Expand Down
18 changes: 12 additions & 6 deletions include/boost/filesystem/path.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ namespace filesystem

path() BOOST_NOEXCEPT {}
path(const path& p) : m_pathname(p.m_pathname) {}
//#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
// path(path&& p) BOOST_NOEXCEPT;
//#endif

template <class Source>
path(Source const& source,
Expand All @@ -151,6 +148,18 @@ namespace filesystem
path(const string_type& s) : m_pathname(s) {}
path(string_type& s) : m_pathname(s) {}

# if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
# if !defined(BOOST_FILESYSTEM_NO_CXX11_DEFAULTED_RVALUE_REFS)
path(path&&) BOOST_NOEXCEPT = default;
path& operator=(path&&) BOOST_NOEXCEPT = default;
# else
path(path&& p) BOOST_NOEXCEPT
{ m_pathname = std::move(p.m_pathname); }
path& operator=(path&& p) BOOST_NOEXCEPT
{ m_pathname = std::move(p.m_pathname); return *this; }
# endif
# endif

template <class Source>
path(Source const& source, const codecvt_type& cvt)
{
Expand Down Expand Up @@ -188,9 +197,6 @@ namespace filesystem
m_pathname = p.m_pathname;
return *this;
}
//#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
// path& operator=(path&& p) BOOST_NOEXCEPT;
//#endif

template <class Source>
typename boost::enable_if<path_traits::is_pathable<
Expand Down
25 changes: 25 additions & 0 deletions test/path_unit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,30 @@ namespace
PATH_IS(x, L"wstring");
}

// test_move_construction_and_assignment -------------------------------------------//

void test_move_construction_and_assignment()
{
std::cout << "testing move_construction_and_assignment..." << std::endl;

# if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
path from("long enough to avoid small object optimization");
path to(std::move(from));
BOOST_TEST(from.empty());
BOOST_TEST(to == "long enough to avoid small object optimization");

path from2("long enough to avoid small object optimization");
path to2;
to2 = std::move(from2);
BOOST_TEST(from2.empty());
BOOST_TEST(to2 == "long enough to avoid small object optimization");
# else
std::cout <<
"Test skipped because compiler does not support move semantics" << std::endl;
# endif

}

// test_appends --------------------------------------------------------------------//

void test_appends()
Expand Down Expand Up @@ -1114,6 +1138,7 @@ int test_main(int, char*[])
test_overloads();
test_constructors();
test_assignments();
test_move_construction_and_assignment();
test_appends();
test_concats();
test_modifiers();
Expand Down

0 comments on commit 9d5415d

Please sign in to comment.