Skip to content

Commit

Permalink
Tidy up constructors and moves vs copies
Browse files Browse the repository at this point in the history
  • Loading branch information
victorreijgwart committed Nov 21, 2024
1 parent 9269a3b commit 620f161
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
13 changes: 9 additions & 4 deletions library/cpp/include/wavemap/core/config/string_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ struct StringList {

// Constructors
StringList() = default;
StringList(ValueType value) : value(std::move(value)) {} // NOLINT
StringList(const ValueType& value) : value(value) {} // NOLINT
StringList(ValueType&& value) : value(std::move(value)) {} // NOLINT

// Assignment operator
StringList& operator=(ValueType rhs) {
StringList& operator=(const ValueType& rhs) {
value = rhs;
return *this;
}
StringList& operator=(ValueType&& rhs) {
value = std::move(rhs);
return *this;
}
Expand All @@ -29,8 +34,8 @@ struct StringList {
bool operator!=(const StringList& rhs) const { return value != rhs.value; }

// Allow implicit conversions to the underlying type
operator ValueType&() { return value; }
operator const ValueType&() const { return value; }
operator ValueType&() { return value; } // NOLINT
operator const ValueType&() const { return value; } // NOLINT

// Method to load from configs
static std::optional<StringList> from(const param::Value& param);
Expand Down
5 changes: 4 additions & 1 deletion library/cpp/include/wavemap/core/data_structure/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ class Image {
PixelT initial_value = data::fill::zero<PixelT>())
: initial_value_(initial_value),
data_(Data::Constant(num_rows, num_columns, initial_value)) {}
explicit Image(Data data, PixelT initial_value = data::fill::zero<PixelT>())
explicit Image(const Data& data,
PixelT initial_value = data::fill::zero<PixelT>())
: initial_value_(initial_value), data_(data) {}
explicit Image(Data&& data, PixelT initial_value = data::fill::zero<PixelT>())
: initial_value_(initial_value), data_(std::move(data)) {}

bool empty() const { return !size(); }
Expand Down
3 changes: 2 additions & 1 deletion library/cpp/include/wavemap/core/data_structure/pointcloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class Pointcloud {
using Data = Eigen::Matrix<FloatingPoint, kDim, Eigen::Dynamic>;

Pointcloud() = default;
explicit Pointcloud(Data pointcloud) : data_(std::move(pointcloud)) {}
explicit Pointcloud(const Data& pointcloud) : data_(pointcloud) {}
explicit Pointcloud(Data&& pointcloud) : data_(std::move(pointcloud)) {}

template <typename PointContainer>
explicit Pointcloud(const PointContainer& point_container) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PosedObject : public ObjectT {
using ObjectT::ObjectT;

template <typename... Args>
explicit PosedObject(Transformation3D T_W_C, Args... args)
explicit PosedObject(const Transformation3D& T_W_C, Args... args)
: ObjectT(std::forward<Args>(args)...) {
setPose(T_W_C);
}
Expand Down
3 changes: 1 addition & 2 deletions library/cpp/include/wavemap/core/utils/print/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ inline std::string sequence(const SequenceT& sequence,
return std::accumulate(std::next(sequence.cbegin()), sequence.cend(),
print::element(sequence[0]),
[separator](auto str, const auto& el) -> std::string {
return std::move(str) + separator +
print::element(el);
return str + separator + print::element(el);
});
}
} // namespace wavemap::print
Expand Down

0 comments on commit 620f161

Please sign in to comment.