Skip to content

Commit

Permalink
feat(core): add memory::move
Browse files Browse the repository at this point in the history
  • Loading branch information
RiscadoA committed Sep 19, 2023
1 parent 9929e70 commit 05efbd2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ set(CUBOS_CORE_INCLUDE
"include/cubos/core/settings.hpp"
"include/cubos/core/thread_pool.hpp"

"include/cubos/core/memory/move.hpp"
"include/cubos/core/memory/stream.hpp"
"include/cubos/core/memory/standard_stream.hpp"
"include/cubos/core/memory/buffer_stream.hpp"
Expand Down
44 changes: 44 additions & 0 deletions core/include/cubos/core/memory/move.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/// @file
/// @brief Function @ref cubos::core::memory::move.
/// @ingroup core-memory

#pragma once

namespace cubos::core::memory
{
/// @brief Provides a type which is the same as the given type, but without any references.
/// @note This is a replacement for `std::remove_reference`, which allows us to avoid including
/// the entire `<type_traits>` header.
/// @tparam T
template <typename T>
struct RemoveReference
{
/// @brief Type without references.
using Type = T;
};

template <typename T>
struct RemoveReference<T&>
{
using Type = T;
};

template <typename T>
struct RemoveReference<T&&>
{
using Type = T;
};

/// @brief Returns an R-value reference to the given value
/// @note This is a replacement for `std::move`, which allows us to avoid including the entire
/// `<utility>` header.
/// @tparam T Value type.
/// @param value Value to move.
/// @return Moved value.
/// @ingroup core-memory
template <typename T>
typename RemoveReference<T>::Type&& move(T&& value)
{
return static_cast<typename RemoveReference<T>::Type&&>(value);
}
} // namespace cubos::core::memory

0 comments on commit 05efbd2

Please sign in to comment.