From 8e5fa8ef33e9201470b58b1e4ab799bc480da65e Mon Sep 17 00:00:00 2001 From: Shane Grant Date: Sun, 22 Dec 2013 12:14:23 -0800 Subject: [PATCH] testing macros for gcc 4.7 --- include/cereal/details/traits.hpp | 17 +++++++++++++ sandbox_vs.cpp | 42 +------------------------------ 2 files changed, 18 insertions(+), 41 deletions(-) diff --git a/include/cereal/details/traits.hpp b/include/cereal/details/traits.hpp index 8ca4a45a..345c363d 100644 --- a/include/cereal/details/traits.hpp +++ b/include/cereal/details/traits.hpp @@ -30,6 +30,10 @@ #ifndef CEREAL_DETAILS_TRAITS_HPP_ #define CEREAL_DETAILS_TRAITS_HPP_ +#if (__GNUC__ == 4 && __GNUC_MINOR__ <= 7) +#define CEREAL_OLDER_GCC +#endif + #include #include #include @@ -43,9 +47,21 @@ namespace cereal typedef std::true_type yes; typedef std::false_type no; + #ifdef CEREAL_OLDER_GCC // when VS supports better SFINAE, we can use this as the default + template struct Void { typedef void type; }; + #endif // CEREAL_OLDER_GCC + //! Creates a test for whether a non const member function exists /*! This creates a class derived from std::integral_constant that will be true if the type has the proper member function for the given archive. */ + #ifdef CEREAL_OLDER_GCC + #define CEREAL_MAKE_HAS_MEMBER_TEST(name) \ + template \ + struct has_member_##name : no; \ + template \ + struct has_member_##name(), std::declval() ) ) >::type> : yes {}; + #else // NOT CEREAL_OLDER_GCC #define CEREAL_MAKE_HAS_MEMBER_TEST(name) \ namespace detail \ { \ @@ -61,6 +77,7 @@ namespace cereal } /* end namespace detail */ \ template \ struct has_member_##name : std::integral_constant::value> {} + #endif // NOT CEREAL_OLDER_GCC //! Creates a test for whether a non const non-member function exists /*! This creates a class derived from std::integral_constant that will be true if diff --git a/sandbox_vs.cpp b/sandbox_vs.cpp index aae34c7f..910d67dc 100644 --- a/sandbox_vs.cpp +++ b/sandbox_vs.cpp @@ -174,47 +174,7 @@ int main() std::cout << typeid(A).name() << std::endl; std::cout << typeid(cereal::traits::has_load_and_allocate).name() << std::endl; - //Archive a; - //T t; + // extra testing - //cereal::access::member_save( a, t ); - //cereal::access::member_load( a, t ); - //cereal::access::member_serialize( a, t ); - - //std::stringstream ss; - //{ - // cereal::JSONOutputArchive ar( ss ); - // ar( 5 ); - // ar( cereal::make_nvp("hello", 2.4f ) ); - // std::string s = "hey yo"; - // ar( CEREAL_NVP( s ) ); - // int darp [] = { 1, 2, 3 }; - // ar.saveBinaryValue( darp, sizeof(int) * 3, "darp" ); - // std::unique_ptr ptr( new B() ); - // ar( CEREAL_NVP( ptr ) ); - //} - //{ - // cereal::JSONInputArchive ar( ss ); - // int x; - // ar( x ); - // assert( x == 5 ); - // float f; - // ar( f ); - // assert( f == 2.4f ); - // std::string s; - // ar( s ); - // assert( s == "hey yo" ); - // int darp[3]; - // ar.loadBinaryValue( darp, sizeof(int) * 3 ); - // assert( darp[0] == 1 ); - // assert( darp[1] == 2 ); - // assert( darp[2] == 3 ); - // std::unique_ptr ptr; - // std::cout << "----------" << std::endl; - // std::cout << std::is_default_constructible::value << std::endl; - // std::cout << cereal::traits::has_load_and_allocate::value << std::endl; - // ar( ptr ); - //} - return 0; }