Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add move implementation which asserts on providing const argument #544

Merged
merged 1 commit into from
Apr 8, 2024

Conversation

dhaibatc
Copy link
Contributor

Many a times programmers apply std::move on a const-lvalue or lvalue-const-reference, either directly or indirectly (lambda captures are implicitly immutable, unless the lambda is marked mutable), expecting the move-constructor or move-assignment to kick in, but that does not happen.
This version of stlab::move(moved_object); compile-time asserts when the type passed is const

@@ -126,6 +126,16 @@ constexpr std::decay_t<T> copy(T&& value) noexcept(noexcept(std::decay_t<T>{

/**************************************************************************************************/

/// A standard move implementation but with a compile-time check for const types.
template <class T>
constexpr std::remove_reference_t<T>&& move(T&& t) noexcept {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be named strict_move?

Copy link
Member

@sean-parent sean-parent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sean-parent sean-parent merged commit b335261 into stlab:main Apr 8, 2024
6 checks passed
@dhaibatc dhaibatc deleted the dchaudhu/asserted-move branch April 16, 2024 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants