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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions docs/libraries/utility.hpp/f_move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
layout: function
title: move
hyde:
owner: dhaibatc
brief: __INLINED__
tags:
- function
inline:
brief:
- A standard move implementation but with a compile-time check for const types.
defined_in_file: utility.hpp
overloads:
"template <class T>\nconstexpr std::remove_reference_t<T> && move(T &&)":
arguments:
- description: __OPTIONAL__
name: t
type: T &&
description: __INLINED__
inline:
description:
- A standard move implementation but with a compile-time check for const types.
return: __OPTIONAL__
signature_with_names: "template <class T>\nconstexpr std::remove_reference_t<T> && move(T && t)"
namespace:
- stlab
- v2
---
10 changes: 10 additions & 0 deletions stlab/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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?

static_assert(!std::is_const_v<std::remove_reference_t<T>>,
"move of const type will unintentionally decay to copy");
return static_cast<std::remove_reference_t<T>&&>(t);
}

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

} // namespace STLAB_VERSION_NAMESPACE()
} // namespace stlab

Expand Down
Loading