diff --git a/Makefile b/Makefile index aca31336..e5361473 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ CPPFLAGS=-std=c++11 -I./include -Wall -Werror -g -Wextra -Wshadow -pedantic -CXX=g++-4.7 +CXX=g++ COVERAGE_OUTPUT=out -all: unittests sandbox performance sandbox_rtti sandbox_json +all: unittests sandbox sandbox_vs performance sandbox_rtti sandbox_json sandbox: sandbox.cpp ${CXX} sandbox.cpp -o sandbox ${CPPFLAGS} diff --git a/include/cereal/details/traits.hpp b/include/cereal/details/traits.hpp index e7cece51..414ed82b 100644 --- a/include/cereal/details/traits.hpp +++ b/include/cereal/details/traits.hpp @@ -101,6 +101,14 @@ namespace cereal //! Creates a test for whether a non const member function exists with a version parameter /*! 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_VERSIONED_TEST(name) \ + template \ + struct has_member_versioned_##name : no {}; \ + template \ + struct has_member_versioned_##name(), std::declval(), 0 ) ) >::type> : yes {} + #else // NOT CEREAL_OLDER_GCC #define CEREAL_MAKE_HAS_MEMBER_VERSIONED_TEST(name) \ namespace detail \ { \ @@ -116,6 +124,7 @@ namespace cereal } /* end namespace detail */ \ template \ struct has_member_versioned_##name : std::integral_constant::value> {} + #endif // NOT CEREAL_OLDER_GCC //! Creates a test for whether a non const non-member function exists with a version parameter /*! This creates a class derived from std::integral_constant that will be true if @@ -194,6 +203,21 @@ namespace cereal template struct has_member_save_impl { + #ifdef CEREAL_OLDER_GCC + template + struct test : no {}; + template + struct test(), std::declval() ) ) >::type> : yes {}; + static const bool value = test(); + + template + struct test2 : no {}; + template + struct test2(), std::declval::type&>() ) ) >::type> : yes {}; + static const bool not_const_type = test2(); + #else // NOT CEREAL_OLDER_GCC ========================================= template static auto test(int) -> decltype( cereal::access::member_save( std::declval(), std::declval() ), yes()); template @@ -205,6 +229,7 @@ namespace cereal template static no test2(...); static const bool not_const_type = std::is_same(0)), yes>::value; + #endif // NOT CEREAL_OLDER_GCC }; } // end namespace detail @@ -224,6 +249,21 @@ namespace cereal template struct has_member_versioned_save_impl { + #ifdef CEREAL_OLDER_GCC + template + struct test : no {}; + template + struct test(), std::declval(), 0 ) ) >::type> : yes {}; + static const bool value = test(); + + template + struct test2 : no {}; + template + struct test2(), std::declval::type&>(), 0 ) ) >::type> : yes {}; + static const bool not_const_type = test2(); + #else // NOT CEREAL_OLDER_GCC ========================================= template static auto test(int) -> decltype( cereal::access::member_save( std::declval(), std::declval(), 0 ), yes()); template @@ -235,6 +275,7 @@ namespace cereal template static no test2(...); static const bool not_const_type = std::is_same(0)), yes>::value; + #endif // NOT_CEREAL_OLDER_GCC }; } // end namespace detail diff --git a/include/cereal/types/boost_variant.hpp b/include/cereal/types/boost_variant.hpp index 615404f1..b8df43fc 100644 --- a/include/cereal/types/boost_variant.hpp +++ b/include/cereal/types/boost_variant.hpp @@ -56,7 +56,7 @@ namespace cereal //! @internal template typename std::enable_if::value, void>::type - load_variant(Archive & ar, int target, Variant & variant) + load_variant(Archive & /*ar*/, int /*target*/, Variant & /*variant*/) { throw ::cereal::Exception("Error traversing variant during load"); } diff --git a/include/cereal/types/map.hpp b/include/cereal/types/map.hpp index df8bd2b5..ac851474 100644 --- a/include/cereal/types/map.hpp +++ b/include/cereal/types/map.hpp @@ -65,7 +65,11 @@ namespace cereal typename MapT::mapped_type value; ar( make_map_item(key, value) ); + #ifdef CEREAL_OLDER_GCC + hint = map.insert( hint, std::make_pair(std::move(key), std::move(value)) ); + #else // NOT CEREAL_OLDER_GCC hint = map.emplace_hint( hint, std::move( key ), std::move( value ) ); + #endif // NOT CEREAL_OLDER_GCC } } } diff --git a/include/cereal/types/set.hpp b/include/cereal/types/set.hpp index f726e246..5eaf4e1d 100644 --- a/include/cereal/types/set.hpp +++ b/include/cereal/types/set.hpp @@ -62,7 +62,11 @@ namespace cereal typename SetT::key_type key; ar( key ); + #ifdef CEREAL_OLDER_GCC + hint = set.insert( hint, std::move( key ) ); + #else // NOT CEREAL_OLDER_GCC hint = set.emplace_hint( hint, std::move( key ) ); + #endif // NOT CEREAL_OLDER_GCC } } } diff --git a/sandbox_vs.cpp b/sandbox_vs.cpp index 910d67dc..84b28b7f 100644 --- a/sandbox_vs.cpp +++ b/sandbox_vs.cpp @@ -45,40 +45,40 @@ struct Archive {}; struct Test { template - void serialzize( Archive & ar ) + void serialzize( Archive & ) { std::cout << "hey there" << std::endl; } template - void save( Archive & ar ) const + void save( Archive & ) const { std::cout << "saved by the bell" << std::endl; } template - void load( Archive & ar ) + void load( Archive & ) { std::cout << "locked and loaded" << std::endl; } template - static Test * load_and_allocate( Archive & ar ) + static Test * load_and_allocate( Archive & ) { return new Test(); } }; template -void serialize( Archive & ar, Test & t ) +void serialize( Archive &, Test & ) { } template -void load( Archive & ar, Test & t ) +void load( Archive &, Test & ) { } template -void save( Archive & ar, Test const & t ) +void save( Archive &, Test const & ) { } namespace cereal @@ -87,7 +87,7 @@ namespace cereal struct LoadAndAllocate { template - static Test * load_and_allocate( Archive & ar ) + static Test * load_and_allocate( Archive & ) { return new Test(); } @@ -104,7 +104,7 @@ struct B : A void foo() {} template - void serialize( Archive & ar ) + void serialize( Archive & ) { std::cout << "i'm in your b" << std::endl; } diff --git a/unittests.cpp b/unittests.cpp index f1ad4ba6..a6bbe854 100644 --- a/unittests.cpp +++ b/unittests.cpp @@ -811,8 +811,13 @@ void test_map_memory() for(int j=0; j<100; ++j) { + #ifdef CEREAL_OLDER_GCC + o_uniqueptrMap.insert( std::make_pair(random_value(gen), std::unique_ptr( new int( random_value(gen) ) )) ); + o_sharedptrMap.insert( std::make_pair(random_value(gen), std::make_shared( random_value(gen) )) ); + #else // NOT CEREAL_OLDER_GCC o_uniqueptrMap.emplace( random_value(gen), std::unique_ptr( new int( random_value(gen) ) ) ); o_sharedptrMap.emplace( random_value(gen), std::make_shared( random_value(gen) ) ); + #endif // NOT CEREAL_OLDER_GCC } std::ostringstream os;