AuroraRuntime/Include/auROXTL/auCopyMoveUtils.hpp
Reece 74a0e92d32 [+] Document auCopyMoveUtils
[*] Memory Model
[*] TryConstruct shall permit extensions of the bool class (use it like a tag)
[*] Formatting
2022-03-26 12:02:08 +00:00

76 lines
1.6 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: auCopyMoveUtils.hpp
Date: 2022-2-1
Author: Reece
***/
#pragma once
/**
* @brief Upcasts R-Value upcastable @param arg.
* For an L-Value equivalent hint, use AuReference
* @tparam T
* @param arg
* @return
*/
template <class T>
constexpr AuRemoveReference_t<T> &&AuMove(T &&arg)
{
return static_cast<AuRemoveReference_t<T> &&>(arg);
}
/**
* @brief Upcasts L-Value upcastable @param arg.
* For an R-Value equivalent hint, use AuMove
* @tparam T An expression to implicitly upcast to an L-value
* @param arg
* @return
*/
template <class T>
constexpr T &AuReference(T &arg)
{
return static_cast<T &>(arg);
}
/**
* @brief Preserves R or L value without reducing; implicit AuMove or AuReference
* @tparam T An expression to implicitly upcast to an R-value
* @param arg
* @return
*/
template <class T>
constexpr T &&AuForward(AuRemoveReference_t<T> &arg)
{
return static_cast<T &&>(arg);
}
/**
* @brief Preserves R or L value without reducing; implicit AuMove or AuReference
* @tparam T
* @param arg
* @return
*/
template <class T>
constexpr T &&AuForward(AuRemoveReference_t<T> &&arg)
{
return static_cast<T &&>(arg);
}
template <class T, class U = T>
inline T AuExchange(T &obj, U &&newValue)
{
T oldValue = AuMove(obj);
obj = AuForward<U>(newValue);
return oldValue;
}
#if !defined(AURORA_RUNTIME_SWAP)
#define AURORA_RUNTIME_SWAP std::swap
#endif
template <class T>
inline void AuSwap(T &a, T &b)
{
AURORA_RUNTIME_SWAP(a, b);
}