Skip to content

Commit

Permalink
fix(expression): disable the move constructor for public use to avoid…
Browse files Browse the repository at this point in the history
… undefined behaviour
  • Loading branch information
amitsingh19975 committed Feb 15, 2022
1 parent d3b0b8d commit cf25af7
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions include/boost/numeric/ublas/tensor/expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,18 @@ struct tensor_expression
tensor_expression& operator=(const tensor_expression&) = delete;
constexpr tensor_expression& operator=(tensor_expression&&) noexcept = delete;

/**
* @brief This is the only way to discourage the users from using `std::move` on the local
* expression because it works differently from the standard way to move the objects. This weird
* behaviour is due to `const reference`, which is impossible to move without constructing a new object.
* If the variable goes out of the scope, stored as a `const reference` inside the expression,
* it will be destroyed that will result in a dangling pointer. But this behaviour is helpful
* for the construction of an expression because the expression might contain a `const reference`
* object that will be passed around as a `const reference` rather than a copy, and we do not need to
* construct a whole new chunky object because, under the hood, we are just passing pointers around.
*
*/
protected :
/**
* @brief This is the only way to discourage the users from using `std::move` on the local
* expression because it works differently from the standard way to move the objects. This weird
* behaviour is due to `const reference`, which is impossible to move without constructing a new object.
* If the variable goes out of the scope, stored as a `const reference` inside the expression,
* it will be destroyed that will result in a dangling pointer. But this behaviour is helpful
* for the construction of an expression because the expression might contain a `const reference`
* object that will be passed around as a `const reference` rather than a copy, and we do not need to
* construct a whole new chunky object because, under the hood, we are just passing pointers around.
*
*/
constexpr tensor_expression(tensor_expression&&) noexcept = default;
explicit tensor_expression() = default;

Expand Down Expand Up @@ -184,18 +184,18 @@ struct binary_tensor_expression
[[nodiscard]] inline
constexpr decltype(auto) operator()(size_type i) const { return op(left_expr()(i), right_expr()(i)); }

/**
* @brief This is the only way to discourage the users from using `std::move` on the local
* expression because it works differently from the standard way to move the objects. This weird
* behaviour is due to `const reference`, which is impossible to move without constructing a new object.
* If the variable goes out of the scope, stored as a `const reference` inside the expression,
* it will be destroyed that will result in a dangling pointer. But this behaviour is helpful
* for the construction of an expression because the expression might contain a `const reference`
* object that will be passed around as a `const reference` rather than a copy, and we do not need to
* construct a whole new chunky object because, under the hood, we are just passing pointers around.
*
*/
protected:
/**
* @brief This is the only way to discourage the users from using `std::move` on the local
* expression because it works differently from the standard way to move the objects. This weird
* behaviour is due to `const reference`, which is impossible to move without constructing a new object.
* If the variable goes out of the scope, stored as a `const reference` inside the expression,
* it will be destroyed that will result in a dangling pointer. But this behaviour is helpful
* for the construction of an expression because the expression might contain a `const reference`
* object that will be passed around as a `const reference` rather than a copy, and we do not need to
* construct a whole new chunky object because, under the hood, we are just passing pointers around.
*
*/
constexpr binary_tensor_expression(binary_tensor_expression&& l) noexcept = default;

/// @brief This the only way to access the protected move constructor of other expressions.
Expand Down Expand Up @@ -257,18 +257,18 @@ struct unary_tensor_expression
[[nodiscard]] inline constexpr
decltype(auto) operator()(size_type i) const { return op(expr()(i)); }

/**
* @brief This is the only way to discourage the users from using `std::move` on the local
* expression because it works differently from the standard way to move the objects. This weird
* behaviour is due to `const reference`, which is impossible to move without constructing a new object.
* If the variable goes out of the scope, stored as a `const reference` inside the expression,
* it will be destroyed that will result in a dangling pointer. But this behaviour is helpful
* for the construction of an expression because the expression might contain a `const reference`
* object that will be passed around as a `const reference` rather than a copy, and we do not need to
* construct a whole new chunky object because, under the hood, we are just passing pointers around.
*
*/
protected:
/**
* @brief This is the only way to discourage the users from using `std::move` on the local
* expression because it works differently from the standard way to move the objects. This weird
* behaviour is due to `const reference`, which is impossible to move without constructing a new object.
* If the variable goes out of the scope, stored as a `const reference` inside the expression,
* it will be destroyed that will result in a dangling pointer. But this behaviour is helpful
* for the construction of an expression because the expression might contain a `const reference`
* object that will be passed around as a `const reference` rather than a copy, and we do not need to
* construct a whole new chunky object because, under the hood, we are just passing pointers around.
*
*/
constexpr unary_tensor_expression(unary_tensor_expression&& l) noexcept = default;

/// @brief This the only way to access the protected move constructor of other expressions.
Expand Down

0 comments on commit cf25af7

Please sign in to comment.