niXman / yas

Yet Another Serialization
731 stars 95 forks source link

hen the same object is save/load multiple times, it will always be appended after wstring.bug!!! #138

Closed xushengbo closed 1 year ago

niXman commented 1 year ago

you should use yas::init() for such cases.

the implementation: https://github.com/niXman/yas/blob/master/include/yas/types/utility/init.hpp

example: https://github.com/niXman/yas/blob/master/examples/init/main.cpp#L55

niXman commented 1 year ago

please close this PR.

xushengbo commented 1 year ago

Thanks for your reply, I got the correct result through the example you gave, but don't know how it all happened. Can you explain the function of yas::init() in detail? Thanks again!!

xushengbo commented 1 year ago
template<
     typename Archive
    ,typename DT = typename std::decay<T>::type
    ,bool ok = std::is_fundamental<DT>::value || std::is_enum<DT>::value
>
static Archive& load(Archive &ar, init_wrapper<T> &v, typename std::enable_if<!ok>::type* = nullptr) {
    v.val.clear();

    return ar & v.val;
}

I got it.Thank you!