Как правильно реализовать семантику перемещения с помощью operator+
? Аналогично тому, как это работает для std::string
?
Я попытался сделать следующее, однако я надеялся, что есть более элегантный и, возможно, более правильный способ сделать это:
class path
{
std::vector<std::string> path_;
public:
path& path::operator+=(const path& other)
{
path_.insert(std::begin(path_), std::begin(other.path_), std::end(other.path_));
return *this;
}
path& path::operator+=(path&& other)
{
path_.insert(std::begin(path_), std::make_move_iterator(std::begin(other.path_)), std::make_move_iterator(std::end(other.path_)));
return *this;
}
};
template<typename L, typename R>
typename std::enable_if<std::is_convertible<path, L>::value, path>::type operator+(const L& lhs, const R& rhs)
{
auto tmp = std::forward<L>(lhs);
tmp += std::forward<R>(rhs);
return tmp;
}