Allow writing from pointers

This commit is contained in:
Patrick Urbanke
2024-03-31 11:42:20 +02:00
parent 86f73123d2
commit 12a294af71
-21
View File
@@ -13,39 +13,18 @@ namespace internal {
template <internal::StringLiteral _name, class Type>
inline auto to_ptr_field(Field<_name, Type>& _field) {
if constexpr (std::is_pointer_v<Type>) {
static_assert(always_false_v<Type>,
"Writing from raw pointers is dangerous and "
"therefore unsupported. "
"Please consider using std::unique_ptr, rfl::Box, "
"std::shared_ptr, rfl::Ref or std::optional instead.");
}
using T = std::remove_reference_t<Type>;
return Field<_name, T*>(&_field.value_);
}
template <internal::StringLiteral _name, class Type>
inline auto to_ptr_field(const Field<_name, Type>& _field) {
if constexpr (std::is_pointer_v<Type>) {
static_assert(always_false_v<Type>,
"Writing from raw pointers is dangerous and "
"therefore unsupported. "
"Please consider using std::unique_ptr, rfl::Box, "
"std::shared_ptr, rfl::Ref or std::optional instead.");
}
using T = std::remove_cvref_t<Type>;
return Field<_name, const T*>(&_field.value_);
}
template <class Type>
inline auto to_ptr_field(Flatten<Type>& _field) {
if constexpr (std::is_pointer_v<Type>) {
static_assert(always_false_v<Type>,
"Writing from raw pointers is dangerous and "
"therefore unsupported. "
"Please consider using std::unique_ptr, rfl::Box, "
"std::shared_ptr, rfl::Ref or std::optional instead.");
}
using T = std::remove_reference_t<Type>;
return Flatten<T*>(&_field.value_);
}