You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just discovered cereal and want to transition from Boost. Doing this, I discovered that cereal doesn't seem to be able to handle a special case where Boost did not complain.
I have a std::shared_ptr<T const> amongst my data to save and load. I use binary archives. Everything works fine until saving the data, but when I write the code to load the archive, compilation of my program fails. Here is a minimal example that illustrates the issue:
./lib/cereal/types/memory.hpp:337:7: error: no matching function for call to ‘cereal::BinaryInputArchive::registerSharedPointer(uint32_t&, std::shared_ptr<const int>&)’
ar.registerSharedPointer( id, ptr );
^~
In file included from ./lib/cereal/types/memory.hpp:33,
from src/experiment.cpp:14:
./lib/cereal/cereal.hpp:690:19: note: candidate: ‘void cereal::InputArchive<ArchiveType, Flags>::registerSharedPointer(uint32_t, std::shared_ptr<void>) [with ArchiveType = cereal::BinaryInputArchive; unsigned int Flags = 1; uint32_t = unsigned int]’
inline void registerSharedPointer(std::uint32_t const id, std::shared_ptr<void> ptr)
^~~~~~~~~~~~~~~~~~~~~
./lib/cereal/cereal.hpp:690:19: note: no known conversion for argument 2 from ‘shared_ptr<const int>’ to ‘shared_ptr<void>’
FYI: I am using cereal v1.2.2 and gcc version 8.2.0 on Ubuntu 18.04
If I change std::shared_ptr<int const> foo_; to std::shared_ptr<int> foo_;, it compiles. However, in my actual project, this is not an option. I actually found a workaround to retain my datastructures:
If I use separate save() and load() functions instead of serialize(), I can load the data to a temporary std::sharet_ptr<T> and then manually copy it to the member:
I applied this workaround in my actual project and it seems to work fine. However, it would be nice if cereal would be able to work with std::shared_ptr<T const> natively.
The text was updated successfully, but these errors were encountered:
(Sorry, what I wrote earlier was completely rubbish, please disregard if you saw it).
I figured out how to modify cereal.hpp to realize what you want to do. Again this is not a proper hack but it is working for me for the time being, until the developers will implement a proper version.
This is a known issue in the current release of cereal and will be fixed in version 1.2.3 which should be released soon (likely within days of writing this). In the meantime, you can try using the develop branch. See #417 and #423.
Hi,
I just discovered cereal and want to transition from Boost. Doing this, I discovered that cereal doesn't seem to be able to handle a special case where Boost did not complain.
I have a
std::shared_ptr<T const>
amongst my data to save and load. I use binary archives. Everything works fine until saving the data, but when I write the code to load the archive, compilation of my program fails. Here is a minimal example that illustrates the issue:Compiling fails with following message:
FYI: I am using
cereal v1.2.2
andgcc version 8.2.0
on Ubuntu 18.04If I change
std::shared_ptr<int const> foo_;
tostd::shared_ptr<int> foo_;
, it compiles. However, in my actual project, this is not an option. I actually found a workaround to retain my datastructures:If I use separate
save()
andload()
functions instead ofserialize()
, I can load the data to a temporarystd::sharet_ptr<T>
and then manually copy it to the member:I applied this workaround in my actual project and it seems to work fine. However, it would be nice if cereal would be able to work with
std::shared_ptr<T const>
natively.The text was updated successfully, but these errors were encountered: