Re: [Boost-users] [Serialization] is_serializable trait?

BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_serializable,T,::boost::detail::is_serializable_impl<T>::value)
I tried to implement is_non_intrusively_serializable metafunction, but found no general solution. Although I've impelented it for all types which are instances of some class template. For example, it works correctly for vector<int>, some_class<double, string>, etc. Note that it is possible to create metafunction which determines whether type is instance of class template or not. So, we have the following: - is_intrusivelly_serializable metafunction. - is_class_template_instance metafunction. - is_non_intrusively_serializable metafunction, which currently works only for class template instances. Probably someone can implement the last missing case? That is we need is_non_intrusively_serializable implementation for types, which are not class template instances (int, some_nontemplate_class, etc). Here is is_non_intrusively_serializable restricted to class templates. #include <boost/serialization/serialization.hpp> #include <boost/type_traits/remove_cv.hpp> #include <boost/type_traits/detail/yes_no_type.hpp> #include <boost/preprocessor.hpp> #include <boost/static_assert.hpp> #include <boost/serialization/vector.hpp> namespace detail { struct tag {}; using boost::serialization::serialize; #define BOOST_PP_LOCAL_LIMITS (1, 10) #define BOOST_PP_LOCAL_MACRO(N) \ template < \ class Archive, \ template <BOOST_PP_ENUM_PARAMS(N, class I)> class T, \ BOOST_PP_ENUM_PARAMS(N, class T) \ > \ tag serialize( \ Archive & ar, \ T<BOOST_PP_ENUM_PARAMS(N, T)> &, \ const unsigned \ ); #include BOOST_PP_LOCAL_ITERATE() tag operator,(tag, int); boost::type_traits::no_type check(tag); template <class T> boost::type_traits::yes_type check(T const&); template <class T> struct impl { static typename boost::remove_cv<T>::type & x; static const int & archive; static const unsigned version; static const bool value = sizeof(check((serialize(archive, x, version), 0))) == sizeof(boost::type_traits::yes_type); }; } template <class T> struct is_non_intrusively_serializable : detail::impl<T> {}; template <class T> struct A {}; int main() { BOOST_STATIC_ASSERT( is_non_intrusively_serializable<std::vector<int> >::value); BOOST_STATIC_ASSERT( !is_non_intrusively_serializable<A<int> >::value); } Regards, Roman Perepelitsa Deutsche Bank Moscow +7 (495) 660-74-08 --- This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional EU corporate and regulatory disclosures.
participants (1)
-
Roman Perepelitsa