-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add constructible_utils.hpp
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
core/include/cubos/core/reflection/traits/constructible_utils.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/// @file | ||
/// @brief Utilities for @ref cubos::core::reflection::ConstructibleTrait. | ||
/// @note Avoid using this header as it includes `<type_traits>`. | ||
/// @ingroup core-reflection | ||
|
||
#pragma once | ||
|
||
#include <type_traits> | ||
|
||
#include <cubos/core/reflection/traits/constructible.hpp> | ||
|
||
namespace cubos::core::reflection | ||
{ | ||
template <typename T> | ||
ConstructibleTrait autoConstructibleTrait() | ||
{ | ||
auto builder = ConstructibleTrait::typed<T>(); | ||
|
||
if (std::is_default_constructible<T>::value) | ||
{ | ||
builder = static_cast<ConstructibleTrait::Builder<T>&&>(builder).withDefaultConstructor(); | ||
} | ||
|
||
if (std::is_copy_constructible<T>::value) | ||
{ | ||
builder = static_cast<ConstructibleTrait::Builder<T>&&>(builder).withCopyConstructor(); | ||
} | ||
|
||
if (std::is_move_constructible<T>::value) | ||
{ | ||
builder = static_cast<ConstructibleTrait::Builder<T>&&>(builder).withMoveConstructor(); | ||
} | ||
|
||
return static_cast<ConstructibleTrait::Builder<T>&&>(builder).build(); | ||
} | ||
} // namespace cubos::core::reflection |