Add move constructor and move assignment operator for FileName class

This commit is contained in:
Yuriy Skalko 2021-01-07 02:27:31 +02:00
parent 73df32bec4
commit 854c9de8fa
2 changed files with 26 additions and 4 deletions

View File

@ -158,6 +158,13 @@ FileName::FileName(FileName const & rhs) : d(new Private)
}
FileName::FileName(FileName && rhs) noexcept
: d(rhs.d)
{
rhs.d = nullptr;
}
FileName::FileName(FileName const & rhs, string const & suffix) : d(new Private)
{
set(rhs, suffix);
@ -174,6 +181,15 @@ FileName & FileName::operator=(FileName const & rhs)
}
FileName & FileName::operator=(FileName && rhs) noexcept
{
auto temp = rhs.d;
rhs.d = d;
d = temp;
return *this;
}
bool FileName::empty() const
{
return d->name.empty();

View File

@ -42,15 +42,21 @@ public:
*/
explicit FileName(std::string const & abs_filename);
/// copy constructor.
/// copy constructor
FileName(FileName const &);
/// constructor with base name and suffix.
/// move constructor
FileName(FileName &&) noexcept;
/// constructor with base name and suffix
FileName(FileName const & fn, std::string const & suffix);
///
/// copy assign
FileName & operator=(FileName const &);
/// move assign
FileName & operator=(FileName &&) noexcept;
virtual ~FileName();
/** Set a new filename.
* \param filename the file in question. Must have an absolute path.
@ -219,7 +225,7 @@ private:
bool copyTo(FileName const &, bool, FileNameSet &) const;
///
struct Private;
Private * const d;
Private * d;
};