-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rfl::DefaultIfMissing
processor + Reflector<FixedVector>
#260
Comments
Hi @AnsiV01 , it appears that the move operation is failing. Could you translate the error message to English? |
@liuzicheng1987 Sure:
|
Today I had some free time and decided to poke around in the code of this library and found the reason for the failure. It's because move and copy assignment operator are set as default, and there are other contructors besides them, which makes them treated as delete. And so, for example, I think support for this type of situation could be considered. For example, in my situation, a workaround is to change the aforementioned template <class Target, class Source>
static void move_to(Target* _t, Source* _s) {
if constexpr (std::is_const_v<Target>) {
return move_to(const_cast<std::remove_const_t<Target>*>(_t), _s);
} else if constexpr (!rfl::internal::is_array_v<Source> &&
!std::is_array_v<Target>) {
//*_t = Target(std::move(*_s));
//Workaround
if constexpr (requires { *_t = Target(std::move(*_s)); })
*_t = Target(std::move(*_s));
else if constexpr (requires { _t->assign(_s->begin(), _s->end()); })
_t->assign(_s->begin(), _s->end());
else
static_assert(rfl::always_false_v<Target>, "Unsupported");
//Workaround
} else if constexpr (rfl::internal::is_array_v<Source>) {
static_assert(std::is_array_v<Target>,
"Expected target to be a c-array.");
for (size_t i = 0; i < _s->arr_.size(); ++i) {
move_to(&((*_t)[i]), &(_s->arr_[i]));
}
} else {
for (size_t i = 0; i < _s->size(); ++i) {
move_to(&((*_t)[i]), &((*_s)[i]));
}
}
} |
@AnsiV01 , I see...but this assumes that the underlying container has an assign-method. To be honest, I would assume that the move assignment operator would be implemented for all non-const containers. I don't really see a good reason why the FixedVector library would not support the move assignment operator, but instead support something as non-standard as this assign method. In my view, if the authors of the FixedVector library inadvertently deleted their move assignment operator, this is not something we should fix on our side. Maybe you should file a PR to their library and fix the issue there. |
Hello
I am working on a mini-game where I am using reflect-cpp as a parser for json files and more. At some point I needed to implement support for a custom
FixedVector
class from the fixed_container library (https://github.com/teslamotors/fixed-containers). And here I ran into a problem, because the compiler cannot handle this class if I add aDefaultIfMissing
processor when usingrfl::json::(read/load)
. Below MRE.The compiler (MSVC) reports a problem with the use of the deleted function:
Błąd C2280 „fixed_containers::FixedVector<std::pair<Attributes,__int64>,3,fixed_containers::customize::SequenceContainerAbortChecking<T,3>> &fixed_containers::FixedVector<T,3,fixed_containers::customize::SequenceContainerAbortChecking<T,3>>::operator =(const fixed_containers::FixedVector<T,3,fixed_containers::customize::SequenceContainerAbortChecking<T,3>> &)”: próba odwania do usuniętej funkcji with [ T=std::pair<Attributes,__int64> ] 121 E:\ecpp\ecpp\_third\rfl\parsing\ViewReaderWithDefault.hpp
And when I click on the error it redirects me to this code from the
rfl\parsing\ViewReaderWithDefault.hpp
:My question is whether there is a workaround or fix for this situation, or whether this is a problem that cannot be circumvented by the way the
fixed_container
library is implemented?Thanks for any information.
The text was updated successfully, but these errors were encountered: