diff --git a/src/common/variant.h b/src/common/variant.h index 8ec9ccb7a92acb06417a74d9ebe95189ac9e547f..ca2fcc090769bc49603176dc361d5f8c8e22890c 100644 --- a/src/common/variant.h +++ b/src/common/variant.h @@ -79,13 +79,13 @@ struct Variant { template void Set(Args &&... args) { - helper::Destroy(type_id, &data.data); - new (&data.data) T(std::forward(args)...); + helper::Destroy(type_id, data.data); + new (data.data) T(std::forward(args)...); type_id = typeid(T).hash_code(); } void SetString(std::string &string) { - // helper::Destroy(type_id, &data); + helper::Destroy(type_id, data.data); type_id = typeid(std::string).hash_code(); strcpy(data.data, string.c_str()); } @@ -109,7 +109,7 @@ struct Variant { "stl lib with string copy)"); exit(0); } else if (type_id == typeid(T).hash_code()) { - return *const_cast(reinterpret_cast(&data)); + return *const_cast(reinterpret_cast(data.data)); } else { PADDLE_MOBILE_THROW_EXCEPTION(" bad cast in variant"); exit(0); @@ -122,7 +122,8 @@ struct Variant { static inline size_t invalid_type() { return typeid(void).hash_code(); } typedef VariantHelper helper; size_t type_id; - RawData data; + // todo use an anto size to suite this. + RawData<64> data; }; template