Perfect forward val to utMaybe
parent
9519a62dd2
commit
20755f4200
|
@ -41,6 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <assimp/ai_assert.h>
|
#include <assimp/ai_assert.h>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
|
@ -48,13 +49,14 @@ namespace Assimp {
|
||||||
/// @tparam T The type to store.
|
/// @tparam T The type to store.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct Maybe {
|
struct Maybe {
|
||||||
/// @brief
|
/// @brief
|
||||||
Maybe() = default;
|
Maybe() = default;
|
||||||
|
|
||||||
/// @brief
|
/// @brief
|
||||||
/// @param val
|
/// @param val
|
||||||
explicit Maybe(const T &val) :
|
template <typename U>
|
||||||
_val(val), _valid(true) {}
|
explicit Maybe(U &&val) :
|
||||||
|
_val(std::forward<U>(val)), _valid(true) {}
|
||||||
|
|
||||||
/// @brief Validate the value
|
/// @brief Validate the value
|
||||||
/// @return true if valid.
|
/// @return true if valid.
|
||||||
|
@ -64,11 +66,12 @@ struct Maybe {
|
||||||
|
|
||||||
/// @brief Will assign a value.
|
/// @brief Will assign a value.
|
||||||
/// @param v The new valid value.
|
/// @param v The new valid value.
|
||||||
void Set(T &v) {
|
template <typename U>
|
||||||
|
void Set(U &&v) {
|
||||||
ai_assert(!_valid);
|
ai_assert(!_valid);
|
||||||
|
|
||||||
_valid = true;
|
_valid = true;
|
||||||
_val = v;
|
_val = std::forward<U>(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Will return the value when it is valid.
|
/// @brief Will return the value when it is valid.
|
||||||
|
|
Loading…
Reference in New Issue