Compare commits

..

42 Commits

Author SHA1 Message Date
Peter Dimov 46165e3514 Remove no longer necessary command line options from build/Jamfile, util/test.jam 2024-04-11 03:08:14 +03:00
Robert Ramey a32906b8e6 changes to serialization of variants to support boost/variant, boost/variant2 and std::variant 2024-03-23 16:08:17 -07:00
Robert Ramey 2e044c7384 Merge pull request #310 from boostorg/feature/va-start
Restore removed va_start calls; add missing va_end as reported in #264.
2024-03-23 13:19:52 -07:00
Peter Dimov d52537a5ad Restore removed va_start calls; add missing va_end as reported in #264. 2024-03-14 19:04:57 +02:00
Robert Ramey 2805bc3faa removed test dependency on lexical cast 2024-01-08 22:20:18 -08:00
Robert Ramey a20c4d97c3 removed C++03 dependency from test 2023-11-12 21:05:11 -08:00
Robert Ramey 9aa208d9be made C++ 11 the default 2023-11-02 20:23:32 -07:00
Robert Ramey ff0a5f9f4a corrected inclusion of <optional> 2023-11-02 20:17:08 -07:00
Robert Ramey e01b988e70 Merge branch 'develop'
* develop: (108 commits)
  removed unordered tests
  tests have been taken over by developers of boost unordered
  uploading changes regarding unordered ... uploading tweaks to CMakeLists.txt so accommodate static linking
  imported/implemented boost/serialization/variant  and test_variant
  Remove serialization support from Boost.Unordered containers
  Fix invalid vptr access in extended_type_info_no_rtti constructor
  Fix invalid downcast in ~xml_oarchive_impl
  altered boost optional to depend only public interface functions declared in std::optional. adjusted test_optional to test serialization of both boost::optional and std::optional
  Revert "Add serialization for std::optional"
  fix new requirement - if assigment is not defaulted, copy can't be either
  Fix clang-cl regression introduced by #282
  correction in previous merge
  Remove debug output from util/test.jam
  Fix Sub::operator== signature to avoid ambiguity errors in C++20
  Remove C++03 from GHA, because Variant and LexicalCast no longer compile under C++03
  incremement archive version number fix PR 274 fix PR 283
  committing most pending PRs
  Replace static_cast with reinterpet_cast in interface_oarchive
  Update xml_escape::fill() to default assign bstart, bend to an empty string
  Use the first instance of bos during serialization (for the case when there are multiple instances)
  ...
2023-11-01 14:17:27 -07:00
Robert Ramey e4756b71b5 removed unordered tests 2023-11-01 14:16:26 -07:00
Robert Ramey f3eaf91ca1 tests have been taken over by developers of boost unordered 2023-10-31 14:32:34 -07:00
Robert Ramey a2f93247e2 uploading changes regarding unordered ...
uploading tweaks to CMakeLists.txt so accommodate static linking
2023-10-20 15:20:43 -07:00
Robert Ramey 01c26ba107 Merge pull request #292 from cmazakas/ubsan-fixes-v2
ubsan fixes v2
2023-10-20 13:42:37 -07:00
Robert Ramey 404e0a31ae Merge pull request #289 from cmazakas/unordered-serialization
Remove serialization support from Boost.Unordered containers
2023-10-13 12:48:01 -07:00
Robert Ramey 90e3ce2fb9 cleanup of files which shouldn't be there. 2023-10-10 12:42:47 -07:00
Robert Ramey 897dec4c01 imported/implemented boost/serialization/variant and test_variant
imported/implemented boost/serialization/variant now contains code for serialization of boost::variant, boost::variant2 and std::variant. Care has been taken to depend only on the public interfaces of these types. Hence, it is reasonable to hope that the archives are compatible in that one type could be saved and subsequently loaded into a compatible type.  Hopefully this will be useful in some way.  At a minimum it minimizes code duplication.
2023-09-18 10:49:21 -07:00
Christian Mazakas f28482232d Remove serialization support from Boost.Unordered containers
Unordered now supports its Serialization functions so the headers just need to be updated to keep backwards compatibility
2023-09-11 14:52:51 -07:00
Christian Mazakas 6388138a0c Fix invalid vptr access in extended_type_info_no_rtti constructor
Initializing a base class in the initializer list with a member function in the derived is invalid in gcc as the object isn't fully-formed

We instead just inline the body of `get_key()` which avoids the issue.
2023-09-11 13:59:51 -07:00
Christian Mazakas 8d0fbb79f3 Fix invalid downcast in ~xml_oarchive_impl
The destructor of the xml_oarchive_impl winds up calling `this->windup()` which in turn invokes `this->This()->...` which essentially static_cast's to a Archive, which by this point in time is long-since destructed.

By simply inlining the implementation of windup(), we avoid the UB and minimize the required code changes
2023-09-11 13:59:51 -07:00
Robert Ramey 61a2b12076 altered boost optional to depend only public interface functions declared in std::optional.
adjusted test_optional to test serialization of both boost::optional and std::optional
2023-09-08 09:54:14 -07:00
Robert Ramey 5ba9e77ad6 Merge pull request #299 from boostorg/revert-163-add-std-optional-support
Revert "Add serialization for std::optional"
2023-09-03 14:37:14 -07:00
Robert Ramey 74c46ec43c Revert "Add serialization for std::optional" 2023-09-03 14:36:59 -07:00
Robert Ramey 1af820b02e Merge pull request #163 from sdebionne/add-std-optional-support
Add serialization for std::optional
2023-09-03 14:19:57 -07:00
Robert Ramey cb729f5d88 Merge pull request #148 from sdebionne/add-std-variant-support
Add support for C++17 std::variant
2023-09-03 13:06:00 -07:00
Robert Ramey ae305113ff Merge pull request #287 from olologin/fix_for_multiple_bos_in_process
Use the first instance of bos during serialization
2023-09-01 15:14:12 -07:00
Robert Ramey c241d3485c fix new requirement - if assigment is not defaulted, copy can't be either 2023-08-30 13:16:20 -07:00
Robert Ramey 9cd8257b08 Merge commit '6bf961f31e7e13c18548b553070e132347d2b58b' into develop
* commit '6bf961f31e7e13c18548b553070e132347d2b58b':
  Guard MSVC pragmas from clang-cl
2023-08-29 15:05:10 -07:00
Peter Dimov 030b627dce Fix clang-cl regression introduced by #282 2023-08-28 17:37:15 +03:00
Robert Ramey 14b10185de correction in previous merge 2023-08-27 07:40:09 -07:00
Robert Ramey 0e15a5984b Merge commit 'f395fa35faf32a89de4673fa54635eeb5eb39f0c' into develop
* commit 'f395fa35faf32a89de4673fa54635eeb5eb39f0c':
  Remove debug output from util/test.jam
2023-08-26 22:27:29 -07:00
Robert Ramey dfe5c018f8 Merge commit '48a60a2bbb6b214d3c295fc2943aff22db63a944' into develop
* commit '48a60a2bbb6b214d3c295fc2943aff22db63a944':
  Remove C++03 from GHA, because Variant and LexicalCast no longer compile under C++03
2023-08-26 22:27:05 -07:00
Peter Dimov 52bcaffa8c Fix Sub::operator== signature to avoid ambiguity errors in C++20 2023-08-26 00:08:48 +03:00
Peter Dimov 48a60a2bbb Remove C++03 from GHA, because Variant and LexicalCast no longer compile under C++03 2023-08-25 20:57:19 +03:00
olologin b83e440efe Use the first instance of bos during serialization (for the case when there are multiple instances) 2023-07-20 16:35:37 +03:00
Peter Dimov 6bf961f31e Guard MSVC pragmas from clang-cl 2021-02-28 04:04:15 +02:00
Samuel Debionne 97f7767505 Add support for Boost.Variant2 2020-05-05 19:49:01 +02:00
Samuel Debionne 2bbb0577a9 Add serialialization for std::optional 2020-05-05 11:02:50 +02:00
Samuel Debionne f19034cc9e Add serialize for std::monostate 2020-05-05 11:00:59 +02:00
Samuel Debionne aa4b6422db Fix name clash with boost::variant serialization
Allow serialization of non-copy-constructible types (use move instead)
2020-05-05 11:00:59 +02:00
Samuel Debionne 2dbe7b8005 Require variant header using Boost.Config 2020-05-05 11:00:59 +02:00
Samuel Debionne 1a13d6e552 Add cxxstd=17 to the std::variant test requirements 2020-05-05 11:00:59 +02:00
Samuel Debionne f914a185c3 Add support for std::variant 2020-05-05 11:00:59 +02:00
33 changed files with 859 additions and 1198 deletions
+33 -51
View File
@@ -37,26 +37,8 @@ jobs:
fail-fast: false
matrix:
include:
- toolset: gcc-4.6
cxxstd: "03"
address_model: 64
os: ubuntu-latest
container: ubuntu:16.04
install:
- g++-4.6
sources:
- "ppa:ubuntu-toolchain-r/test"
- toolset: gcc-4.7
cxxstd: "03"
address_model: 64
os: ubuntu-latest
container: ubuntu:16.04
install:
- g++-4.7
sources:
- "ppa:ubuntu-toolchain-r/test"
- toolset: gcc-4.8
cxxstd: "03"
cxxstd: "11"
address_model: 64
os: ubuntu-latest
container: ubuntu:16.04
@@ -65,7 +47,7 @@ jobs:
sources:
- "ppa:ubuntu-toolchain-r/test"
- toolset: gcc-4.9
cxxstd: "03,11"
cxxstd: "11"
address_model: 64
os: ubuntu-latest
container: ubuntu:16.04
@@ -74,79 +56,79 @@ jobs:
sources:
- "ppa:ubuntu-toolchain-r/test"
- toolset: gcc-5
cxxstd: "03,11,14,1z"
cxxstd: "11,14,1z"
address_model: 64
os: ubuntu-latest
container: ubuntu:16.04
install:
- g++-5-multilib
- toolset: gcc-5
cxxstd: "03-gnu,11-gnu,14-gnu,1z-gnu"
cxxstd: "11-gnu,14-gnu,1z-gnu"
address_model: 64
os: ubuntu-latest
container: ubuntu:16.04
install:
- g++-5-multilib
- toolset: gcc-6
cxxstd: "03,11,14,1z"
cxxstd: "11,14,1z"
address_model: 64
os: ubuntu-latest
container: ubuntu:18.04
install:
- g++-6-multilib
- toolset: gcc-7
cxxstd: "03,11,14,17"
cxxstd: "11,14,17"
address_model: 64
os: ubuntu-latest
container: ubuntu:18.04
install:
- g++-7-multilib
- toolset: gcc-8
cxxstd: "03,11,14,17,2a"
cxxstd: "11,14,17,2a"
address_model: 64
os: ubuntu-latest
container: ubuntu:18.04
install:
- g++-8-multilib
- toolset: gcc-9
cxxstd: "03,11,14,17,2a"
cxxstd: "11,14,17,2a"
address_model: 64
os: ubuntu-20.04
install:
- g++-9-multilib
- toolset: gcc-9
cxxstd: "03-gnu,11-gnu,14-gnu,17-gnu,2a-gnu"
cxxstd: "11-gnu,14-gnu,17-gnu,2a-gnu"
address_model: 64
os: ubuntu-20.04
install:
- g++-9-multilib
- toolset: gcc-10
cxxstd: "03,11,14,17,20"
cxxstd: "11,14,17,20"
address_model: 64
os: ubuntu-20.04
install:
- g++-10-multilib
- toolset: gcc-11
cxxstd: "03,11,14,17,20,23"
cxxstd: "11,14,17,20,23"
address_model: 64
os: ubuntu-22.04
install:
- g++-11-multilib
- toolset: gcc-12
cxxstd: "03,11,14,17,20,23"
cxxstd: "11,14,17,20,23"
address_model: 64
os: ubuntu-22.04
install:
- g++-12-multilib
- toolset: gcc-12
cxxstd: "03-gnu,11-gnu,14-gnu,17-gnu,20-gnu,23-gnu"
cxxstd: "11-gnu,14-gnu,17-gnu,20-gnu,23-gnu"
address_model: 64
os: ubuntu-22.04
install:
- g++-12-multilib
- name: UBSAN
toolset: gcc-12
cxxstd: "03,11,20"
cxxstd: "11,20"
address_model: 64
ubsan: 1
os: ubuntu-22.04
@@ -156,49 +138,49 @@ jobs:
# Linux, clang
- toolset: clang
compiler: clang++-3.7
cxxstd: "03,11,14"
cxxstd: "11,14"
os: ubuntu-latest
container: ubuntu:16.04
install:
- clang-3.7
- toolset: clang
compiler: clang++-3.8
cxxstd: "03,11,14"
cxxstd: "11,14"
os: ubuntu-latest
container: ubuntu:16.04
install:
- clang-3.8
- toolset: clang
compiler: clang++-3.9
cxxstd: "03,11,14"
cxxstd: "11,14"
os: ubuntu-latest
container: ubuntu:18.04
install:
- clang-3.9
- toolset: clang
compiler: clang++-4.0
cxxstd: "03,11,14"
cxxstd: "11,14"
os: ubuntu-latest
container: ubuntu:18.04
install:
- clang-4.0
- toolset: clang
compiler: clang++-5.0
cxxstd: "03,11,14,1z"
cxxstd: "11,14,1z"
os: ubuntu-latest
container: ubuntu:18.04
install:
- clang-5.0
- toolset: clang
compiler: clang++-6.0
cxxstd: "03,11,14,17"
cxxstd: "11,14,17"
os: ubuntu-latest
container: ubuntu:18.04
install:
- clang-6.0
- toolset: clang
compiler: clang++-7
cxxstd: "03,11,14,17"
cxxstd: "11,14,17"
os: ubuntu-latest
container: ubuntu:18.04
install:
@@ -206,7 +188,7 @@ jobs:
# Note: clang-8 does not fully support C++20, so it is not compatible with libstdc++-8 in this mode
- toolset: clang
compiler: clang++-8
cxxstd: "03,11,14,17,2a"
cxxstd: "11,14,17,2a"
os: ubuntu-latest
container: ubuntu:18.04
install:
@@ -215,49 +197,49 @@ jobs:
gcc_toolchain: 7
- toolset: clang
compiler: clang++-9
cxxstd: "03,11,14,17,2a"
cxxstd: "11,14,17,2a"
os: ubuntu-20.04
install:
- clang-9
- toolset: clang
compiler: clang++-10
cxxstd: "03,11,14,17,20"
cxxstd: "11,14,17,20"
os: ubuntu-20.04
install:
- clang-10
- toolset: clang
compiler: clang++-11
cxxstd: "03,11,14,17,20"
cxxstd: "11,14,17,20"
os: ubuntu-22.04
install:
- clang-11
- toolset: clang
compiler: clang++-12
cxxstd: "03,11,14,17,20,2b"
cxxstd: "11,14,17,20,2b"
os: ubuntu-22.04
install:
- clang-12
- toolset: clang
compiler: clang++-13
cxxstd: "03,11,14,17,20,2b"
cxxstd: "11,14,17,20,2b"
os: ubuntu-22.04
install:
- clang-13
- toolset: clang
compiler: clang++-14
cxxstd: "03,11,14,17,20,2b"
cxxstd: "11,14,17,20,2b"
os: ubuntu-22.04
install:
- clang-14
- toolset: clang
compiler: clang++-14
cxxstd: "03-gnu,11-gnu,14-gnu,17-gnu,20-gnu,2b-gnu"
cxxstd: "11-gnu,14-gnu,17-gnu,20-gnu,2b-gnu"
os: ubuntu-22.04
install:
- clang-14
- toolset: clang
compiler: clang++-15
cxxstd: "03,11,14,17,20,2b"
cxxstd: "11,14,17,20,2b"
os: ubuntu-22.04
install:
- clang-15
@@ -267,7 +249,7 @@ jobs:
- "https://apt.llvm.org/llvm-snapshot.gpg.key"
- toolset: clang
compiler: clang++-15
cxxstd: "03,11,14,17,20,2b"
cxxstd: "11,14,17,20,2b"
os: ubuntu-22.04
install:
- clang-15
@@ -281,10 +263,10 @@ jobs:
linkflags: -stdlib=libc++
- toolset: clang
cxxstd: "03,11,14,17,2a"
cxxstd: "11,14,17,2a"
os: macos-11
- toolset: clang
cxxstd: "03,11,14,17,20,2b"
cxxstd: "11,14,17,20,2b"
os: macos-12
timeout-minutes: 360
+1 -1
View File
@@ -38,7 +38,7 @@ jobs:
addrmd: 32,64
os: windows-2022
- toolset: gcc
cxxstd: "03,11,14,17,2a"
cxxstd: "11,14,17,2a"
addrmd: 64
os: windows-2019
+16 -23
View File
@@ -1,6 +1,6 @@
# CMake build control file for Serialization Library tests
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.5)
if (POLICY CMP0054)
cmake_policy (SET CMP0054 NEW)
@@ -16,44 +16,43 @@ project("serialization")
# Compiler settings
#
message(STATUS "compiler is ${CMAKE_CXX_COMPILER_ID}" )
message(STATUS "C++ compiler is ${CMAKE_CXX_COMPILER_ID}" )
add_definitions(${Boost_LIB_DIAGNOSTIC_DEFINITIONS})
message(STATUS "C compiler is ${CMAKE_C_COMPILER_ID}" )
if( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
add_definitions( -ftemplate-depth=255 )
# we use gcc to test for C++03 compatibility
add_definitions( -std=c++03 )
message(STATUS "compiler is g++ c++03")
set(COMPILER_SUPPORTS_CXX11 FALSE)
elseif( CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" )
add_definitions( /wd4996 )
message(STATUS "compiler is MSVC")
set(COMPILER_SUPPORTS_CXX11 TRUE)
elseif( CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth=300")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++03")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0" )
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O3" )
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -dead_strip")
set(COMPILER_SUPPORTS_CXX11 FALSE)
set(COMPILER_SUPPORTS_CXX11 TRUE)
endif()
add_definitions( -std=c++11 )
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++03")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
#
# Locate Project Prerequisites
#
# Boost
# note: we're assuming that boost has been built with:
# ./b2 toolset=clang-darwin link=static,shared variant=debug,release stage
#
# Project settings
#
option(BUILD_SHARED_LIBS "Build Shared Libraries" true)
find_package(Boost 1.74 REQUIRED COMPONENTS system filesystem)
find_package(Boost 1.82 REQUIRED COMPONENTS system filesystem)
if(NOT Boost_FOUND)
message("Boost NOT Found!")
@@ -280,14 +279,10 @@ archive_test(test_list A)
archive_test(test_list_ptrs A)
archive_test(test_map A)
archive_test(test_map_boost_unordered A)
CHECK_INCLUDE_FILE_CXX(hash_map HASH_MAP_FOUND)
if(HASH_MAP_FOUND)
archive_test(test_map_hashed A)
endif()
if(COMPILER_SUPPORTS_CXX11)
archive_test(test_map_unordered A)
endif()
archive_test(test_mi)
archive_test(test_multiple_ptrs A)
archive_test(test_multiple_inheritance)
@@ -308,14 +303,10 @@ archive_test(test_recursion A)
archive_test(test_registered)
archive_test(test_set A)
archive_test(test_set_boost_unordered A)
CHECK_INCLUDE_FILE_CXX(hash_set HASH_SET_FOUND)
if(HASH_SET_FOUND)
archive_test(test_set_hashed A)
endif()
if(COMPILER_SUPPORTS_CXX11)
archive_test(test_set_unordered A)
endif()
archive_test(test_shared_ptr)
archive_test(test_shared_ptr_multi_base)
@@ -337,10 +328,12 @@ archive_test(test_valarray)
archive_test(test_variant A)
archive_test(test_vector A)
polymorphic_archive_test(test_dll_exported polymorphic_derived1)
foreach(test_name IN ITEMS ${test_list} )
if(BUILD_SHARED_LIBS)
polymorphic_archive_test(test_dll_exported polymorphic_derived1)
foreach(test_name IN ITEMS ${test_list} )
target_link_libraries(${test_name} dll_polymorphic_derived2 dll_polymorphic_base serialization wserialization)
endforeach()
endforeach()
endif()
polymorphic_archive_test(test_no_rtti polymorphic_base polymorphic_derived1 polymorphic_derived2)
polymorphic_archive_test(test_exported polymorphic_base polymorphic_derived1 polymorphic_derived2)
+1 -13
View File
@@ -107,7 +107,7 @@ WSOURCES =
xml_woarchive
polymorphic_xml_wiarchive
polymorphic_xml_woarchive
$(SOURCES_HAS_STD_WSTREAMBUF)
codecvt_null
;
lib boost_serialization
@@ -118,12 +118,6 @@ lib boost_serialization
<toolset>msvc:<cxxflags>/Gy
<toolset>msvc:<define>_SCL_SECURE_NO_WARNINGS
<toolset>msvc:<define>_CRT_SECURE_NO_WARNINGS
<toolset>clang:<cxxflags>"-fvisibility=hidden -fvisibility-inlines-hidden"
<toolset>gcc:<cxxflags>"-fvisibility=hidden -fvisibility-inlines-hidden"
<toolset>darwin:<cxxflags>"-fvisibility=hidden -fvisibility-inlines-hidden"
<toolset>gcc:<cxxflags>"-ftemplate-depth-255"
<toolset>clang:<cxxflags>"-ftemplate-depth-255"
<toolset>darwin:<cxxflags>"-ftemplate-depth-255"
<link>shared:<define>BOOST_SERIALIZATION_DYN_LINK=1
;
@@ -134,12 +128,6 @@ lib boost_wserialization
<toolset>msvc:<cxxflags>/Gy
<toolset>msvc:<define>_SCL_SECURE_NO_WARNINGS
<toolset>msvc:<define>_CRT_SECURE_NO_WARNINGS
<toolset>clang:<cxxflags>"-fvisibility=hidden -fvisibility-inlines-hidden"
<toolset>gcc:<cxxflags>"-fvisibility=hidden -fvisibility-inlines-hidden"
<toolset>darwin:<cxxflags>"-fvisibility=hidden -fvisibility-inlines-hidden"
<toolset>gcc:<cxxflags>"-ftemplate-depth-255"
<toolset>clang:<cxxflags>"-ftemplate-depth-255"
<toolset>darwin:<cxxflags>"-ftemplate-depth-255"
# note: both serialization and wserialization are conditioned on the this
# switch - don't change it to BOOST_WSERIALIZATION_DYN_LINK
<link>shared:<define>BOOST_SERIALIZATION_DYN_LINK=1
+1
View File
@@ -919,6 +919,7 @@ As of this writing, the library contains serialization of the following boost cl
<li>shared_ptr
<li>auto_ptr (demo)
</ul>
C++17 <code style="white-space: normal">std::variant is supported as well</code>.
Others are being added to the list so check the boost files section and headers for
new implementations!
<hr>
@@ -55,7 +55,7 @@ class helper_collection
collection m_collection;
struct predicate {
// BOOST_DEFAULTED_FUNCTION(predicate(const predicate& rhs) : m_ti(rhs.m_ti), {})
BOOST_DEFAULTED_FUNCTION(predicate(const predicate& rhs), : m_ti(rhs.m_ti) {})
BOOST_DELETED_FUNCTION(predicate & operator=(const predicate & rhs))
public:
const void * const m_ti;
@@ -44,13 +44,6 @@ public:
typedef mpl::bool_<true> is_saving;
// return a pointer to the most derived class
#if BOOST_WORKAROUND(BOOST_GCC_VERSION,>=40900)||\
BOOST_WORKAROUND(BOOST_CLANG,>=1)&&\
(__clang_major__>3 || __clang_major__==3 && __clang_minor__ >= 8)
/* https://github.com/boostorg/poly_collection/issues/15 */
__attribute__((no_sanitize("undefined")))
#endif
Archive * This(){
return static_cast<Archive*>(this);
}
@@ -131,8 +131,9 @@ BOOST_ARCHIVE_DECL
xml_oarchive_impl<Archive>::~xml_oarchive_impl(){
if(boost::core::uncaught_exceptions() > 0)
return;
if(0 == (this->get_flags() & no_header))
this->windup();
if(0 == (this->get_flags() & no_header)){
this->put("</boost_serialization>\n");
}
}
} // namespace archive
+1 -1
View File
@@ -82,7 +82,7 @@ class escape :
}
void increment(){
if(m_bnext != NULL && ++m_bnext < m_bend){
if(m_bnext != m_bend && ++m_bnext < m_bend){
m_current_value = *m_bnext;
return;
}
@@ -18,143 +18,11 @@
// See http://www.boost.org for updates, documentation, and revision history.
#include <boost/config.hpp>
#include <boost/unordered_map.hpp>
#include <boost/serialization/utility.hpp>
#include <boost/serialization/unordered_collections_save_imp.hpp>
#include <boost/serialization/unordered_collections_load_imp.hpp>
#include <boost/serialization/archive_input_unordered_map.hpp>
#include <boost/serialization/split_free.hpp>
namespace boost {
namespace serialization {
template<
class Archive,
class Key,
class T,
class HashFcn,
class EqualKey,
class Allocator
>
inline void save(
Archive & ar,
const boost::unordered_map<Key, T, HashFcn, EqualKey, Allocator> &t,
const unsigned int /*file_version*/
){
boost::serialization::stl::save_unordered_collection<
Archive,
boost::unordered_map<Key, T, HashFcn, EqualKey, Allocator>
>(ar, t);
}
template<
class Archive,
class Key,
class T,
class HashFcn,
class EqualKey,
class Allocator
>
inline void load(
Archive & ar,
boost::unordered_map<Key, T, HashFcn, EqualKey, Allocator> &t,
const unsigned int /*file_version*/
){
boost::serialization::stl::load_unordered_collection<
Archive,
boost::unordered_map<Key, T, HashFcn, EqualKey, Allocator>,
boost::serialization::stl::archive_input_unordered_map<
Archive,
boost::unordered_map<Key, T, HashFcn, EqualKey, Allocator>
>
>(ar, t);
}
// split non-intrusive serialization function member into separate
// non intrusive save/load member functions
template<
class Archive,
class Key,
class T,
class HashFcn,
class EqualKey,
class Allocator
>
inline void serialize(
Archive & ar,
boost::unordered_map<Key, T, HashFcn, EqualKey, Allocator> &t,
const unsigned int file_version
){
boost::serialization::split_free(ar, t, file_version);
}
// unordered_multimap
template<
class Archive,
class Key,
class HashFcn,
class T,
class EqualKey,
class Allocator
>
inline void save(
Archive & ar,
const boost::unordered_multimap<Key, T, HashFcn, EqualKey, Allocator> &t,
const unsigned int /*file_version*/
){
boost::serialization::stl::save_unordered_collection<
Archive,
boost::unordered_multimap<Key, T, HashFcn, EqualKey, Allocator>
>(ar, t);
}
template<
class Archive,
class Key,
class T,
class HashFcn,
class EqualKey,
class Allocator
>
inline void load(
Archive & ar,
boost::unordered_multimap<
Key, T, HashFcn, EqualKey, Allocator
> &t,
const unsigned int /*file_version*/
){
boost::serialization::stl::load_unordered_collection<
Archive,
boost::unordered_multimap<Key, T, HashFcn, EqualKey, Allocator>,
boost::serialization::stl::archive_input_unordered_multimap<
Archive,
boost::unordered_multimap<Key, T, HashFcn, EqualKey, Allocator>
>
>(ar, t);
}
// split non-intrusive serialization function member into separate
// non intrusive save/load member functions
template<
class Archive,
class Key,
class T,
class HashFcn,
class EqualKey,
class Allocator
>
inline void serialize(
Archive & ar,
boost::unordered_multimap<Key, T, HashFcn, EqualKey, Allocator> &t,
const unsigned int file_version
){
boost::serialization::split_free(ar, t, file_version);
}
} // namespace serialization
} // namespace boost
#include <boost/static_assert.hpp>
BOOST_STATIC_ASSERT_MSG(
false,
"Boost.Unordered now provides its own Serialization support. "
"This header is no longer necessary and is now deprecated."
)
#endif // BOOST_SERIALIZATION_BOOST_SERIALIZATION_UNORDERED_MAP_HPP
@@ -17,134 +17,11 @@
// See http://www.boost.org for updates, documentation, and revision history.
#include <boost/config.hpp>
#include <boost/unordered_set.hpp>
#include <boost/serialization/unordered_collections_save_imp.hpp>
#include <boost/serialization/unordered_collections_load_imp.hpp>
#include <boost/serialization/archive_input_unordered_set.hpp>
#include <boost/serialization/split_free.hpp>
namespace boost {
namespace serialization {
template<
class Archive,
class Key,
class HashFcn,
class EqualKey,
class Allocator
>
inline void save(
Archive & ar,
const boost::unordered_set<Key, HashFcn, EqualKey, Allocator> &t,
const unsigned int /*file_version*/
){
boost::serialization::stl::save_unordered_collection<
Archive,
boost::unordered_set<Key, HashFcn, EqualKey, Allocator>
>(ar, t);
}
template<
class Archive,
class Key,
class HashFcn,
class EqualKey,
class Allocator
>
inline void load(
Archive & ar,
boost::unordered_set<Key, HashFcn, EqualKey, Allocator> &t,
const unsigned int /*file_version*/
){
boost::serialization::stl::load_unordered_collection<
Archive,
boost::unordered_set<Key, HashFcn, EqualKey, Allocator>,
boost::serialization::stl::archive_input_unordered_set<
Archive,
boost::unordered_set<Key, HashFcn, EqualKey, Allocator>
>
>(ar, t);
}
// split non-intrusive serialization function member into separate
// non intrusive save/load member functions
template<
class Archive,
class Key,
class HashFcn,
class EqualKey,
class Allocator
>
inline void serialize(
Archive & ar,
boost::unordered_set<Key, HashFcn, EqualKey, Allocator> &t,
const unsigned int file_version
){
boost::serialization::split_free(ar, t, file_version);
}
// unordered_multiset
template<
class Archive,
class Key,
class HashFcn,
class EqualKey,
class Allocator
>
inline void save(
Archive & ar,
const boost::unordered_multiset<Key, HashFcn, EqualKey, Allocator> &t,
const unsigned int /*file_version*/
){
boost::serialization::stl::save_unordered_collection<
Archive,
boost::unordered_multiset<Key, HashFcn, EqualKey, Allocator>
>(ar, t);
}
template<
class Archive,
class Key,
class HashFcn,
class EqualKey,
class Allocator
>
inline void load(
Archive & ar,
boost::unordered_multiset<Key, HashFcn, EqualKey, Allocator> &t,
const unsigned int /*file_version*/
){
boost::serialization::stl::load_unordered_collection<
Archive,
boost::unordered_multiset<Key, HashFcn, EqualKey, Allocator>,
boost::serialization::stl::archive_input_unordered_multiset<
Archive,
boost::unordered_multiset<Key, HashFcn, EqualKey, Allocator>
>
>(ar, t);
}
// split non-intrusive serialization function member into separate
// non intrusive save/load member functions
template<
class Archive,
class Key,
class HashFcn,
class EqualKey,
class Allocator
>
inline void serialize(
Archive & ar,
boost::unordered_multiset<Key, HashFcn, EqualKey, Allocator> &t,
const unsigned int file_version
){
boost::serialization::split_free(ar, t, file_version);
}
} // namespace serialization
} // namespace boost
#include <boost/static_assert.hpp>
BOOST_STATIC_ASSERT_MSG(
false,
"Boost.Unordered now provides its own Serialization support. "
"This header is no longer necessary and is now deprecated."
)
#endif // BOOST_SERIALIZATION_BOOST_UNORDERED_SET_HPP
@@ -100,13 +100,9 @@ class extended_type_info_no_rtti :
}
};
public:
#if BOOST_WORKAROUND(BOOST_GCC_VERSION,>=40900)||\
BOOST_WORKAROUND(BOOST_CLANG,>=1)&&\
(__clang_major__>3 || __clang_major__==3 && __clang_minor__ >= 8)
__attribute__((no_sanitize("undefined")))
#endif
extended_type_info_no_rtti() :
no_rtti_system::extended_type_info_no_rtti_0(get_key())
no_rtti_system::extended_type_info_no_rtti_0(
action<guid_defined< T >::value >::invoke())
{
key_register();
}
@@ -133,24 +129,26 @@ public:
}
void * construct(unsigned int count, ...) const BOOST_OVERRIDE {
// count up the arguments
void * r = NULL;
std::va_list ap;
va_start(ap, count);
switch(count){
case 0:
return factory<typename boost::remove_const< T >::type, 0>(ap);
r = factory<typename boost::remove_const< T >::type, 0>(ap);
case 1:
return factory<typename boost::remove_const< T >::type, 1>(ap);
r = factory<typename boost::remove_const< T >::type, 1>(ap);
case 2:
return factory<typename boost::remove_const< T >::type, 2>(ap);
r = factory<typename boost::remove_const< T >::type, 2>(ap);
case 3:
return factory<typename boost::remove_const< T >::type, 3>(ap);
r = factory<typename boost::remove_const< T >::type, 3>(ap);
case 4:
return factory<typename boost::remove_const< T >::type, 4>(ap);
r = factory<typename boost::remove_const< T >::type, 4>(ap);
default:
BOOST_ASSERT(false); // too many arguments
// throw exception here?
return NULL;
}
va_end(ap);
return r;
}
void destroy(void const * const p) const BOOST_OVERRIDE {
boost::serialization::access::destroy(
@@ -112,24 +112,26 @@ public:
}
void * construct(unsigned int count, ...) const BOOST_OVERRIDE {
// count up the arguments
void * r = NULL;
std::va_list ap;
va_start(ap, count);
switch(count){
case 0:
return factory<typename boost::remove_const< T >::type, 0>(ap);
r = factory<typename boost::remove_const< T >::type, 0>(ap);
case 1:
return factory<typename boost::remove_const< T >::type, 1>(ap);
r = factory<typename boost::remove_const< T >::type, 1>(ap);
case 2:
return factory<typename boost::remove_const< T >::type, 2>(ap);
r = factory<typename boost::remove_const< T >::type, 2>(ap);
case 3:
return factory<typename boost::remove_const< T >::type, 3>(ap);
r = factory<typename boost::remove_const< T >::type, 3>(ap);
case 4:
return factory<typename boost::remove_const< T >::type, 4>(ap);
r = factory<typename boost::remove_const< T >::type, 4>(ap);
default:
BOOST_ASSERT(false); // too many arguments
// throw exception here?
return NULL;
}
va_end(ap);
return r;
}
void destroy(void const * const p) const BOOST_OVERRIDE {
boost::serialization::access::destroy(
+87 -23
View File
@@ -7,16 +7,18 @@
// Provides non-intrusive serialization for boost::optional.
#ifndef BOOST_SERIALIZATION_OPTIONAL_HPP_
#define BOOST_SERIALIZATION_OPTIONAL_HPP_
#ifndef BOOST_SERIALIZATION_OPTIONAL_HPP
#define BOOST_SERIALIZATION_OPTIONAL_HPP
#if defined(_MSC_VER)
# pragma once
#endif
#include <boost/config.hpp>
#include <boost/optional.hpp>
#ifndef BOOST_NO_CXX17_HDR_OPTIONAL
#include <optional>
#endif
#include <boost/serialization/item_version_type.hpp>
#include <boost/serialization/library_version_type.hpp>
@@ -30,41 +32,43 @@
// namespace - boost::serialization
namespace boost {
namespace serialization {
namespace detail {
template<class Archive, class T>
void save(
// OT is of the form optional<T>
template<class Archive, class OT>
void save_impl(
Archive & ar,
const boost::optional< T > & t,
const unsigned int /*version*/
const OT & ot
){
// It is an inherent limitation to the serialization of optional.hpp
// that the underlying type must be either a pointer or must have a
// default constructor. It's possible that this could change sometime
// in the future, but for now, one will have to work around it. This can
// be done by serialization the optional<T> as optional<T *>
#if ! defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
#ifndef BOOST_NO_CXX11_HDR_TYPE_TRAITS
BOOST_STATIC_ASSERT(
boost::serialization::detail::is_default_constructible<T>::value
|| boost::is_pointer<T>::value
boost::serialization::detail::is_default_constructible<typename OT::value_type>::value
|| boost::is_pointer<typename OT::value_type>::value
);
#endif
const bool tflag = t.is_initialized();
const bool tflag(ot);
ar << boost::serialization::make_nvp("initialized", tflag);
if (tflag){
ar << boost::serialization::make_nvp("value", *t);
ar << boost::serialization::make_nvp("value", *ot);
}
}
template<class Archive, class T>
void load(
// OT is of the form optional<T>
template<class Archive, class OT>
void load_impl(
Archive & ar,
boost::optional< T > & t,
OT & ot,
const unsigned int version
){
bool tflag;
ar >> boost::serialization::make_nvp("initialized", tflag);
if(! tflag){
t.reset();
ot.reset();
return;
}
@@ -77,26 +81,86 @@ void load(
ar >> BOOST_SERIALIZATION_NVP(item_version);
}
}
if(! t.is_initialized())
t = T();
ar >> boost::serialization::make_nvp("value", *t);
typename OT::value_type t;
ar >> boost::serialization::make_nvp("value",t);
ot = t;
}
} // detail
template<class Archive, class T>
void save(
Archive & ar,
const boost::optional< T > & ot,
const unsigned int /*version*/
){
detail::save_impl(ar, ot);
}
#ifndef BOOST_NO_CXX17_HDR_OPTIONAL
template<class Archive, class T>
void save(
Archive & ar,
const std::optional< T > & ot,
const unsigned int /*version*/
){
detail::save_impl(ar, ot);
}
#endif
template<class Archive, class T>
void load(
Archive & ar,
boost::optional< T > & ot,
const unsigned int version
){
detail::load_impl(ar, ot, version);
}
#ifndef BOOST_NO_CXX17_HDR_OPTIONAL
template<class Archive, class T>
void load(
Archive & ar,
std::optional< T > & ot,
const unsigned int version
){
detail::load_impl(ar, ot, version);
}
#endif
template<class Archive, class T>
void serialize(
Archive & ar,
boost::optional< T > & t,
boost::optional< T > & ot,
const unsigned int version
){
boost::serialization::split_free(ar, t, version);
boost::serialization::split_free(ar, ot, version);
}
#ifndef BOOST_NO_CXX17_HDR_OPTIONAL
template<class Archive, class T>
void serialize(
Archive & ar,
std::optional< T > & ot,
const unsigned int version
){
boost::serialization::split_free(ar, ot, version);
}
#endif
template<class T>
struct version<boost::optional<T> > {
struct version<boost::optional<T> >{
BOOST_STATIC_CONSTANT(int, value = 1);
};
#ifndef BOOST_NO_CXX17_HDR_OPTIONAL
template<class T>
struct version<std::optional<T> >{
BOOST_STATIC_CONSTANT(int, value = 1);
};
#endif
} // serialization
} // boost
#endif // BOOST_SERIALIZATION_OPTIONAL_HPP_
#endif // BOOST_SERIALIZATION_OPTIONAL_HPP
+1 -3
View File
@@ -31,12 +31,11 @@ namespace archive {
namespace serialization {
//namespace detail {
template<class Archive, class T>
struct free_saver {
static void invoke(
Archive & ar,
const T & t,
const T & t,
const unsigned int file_version
){
// use function overload (version_type) to workaround
@@ -58,7 +57,6 @@ struct free_loader {
load(ar, t, v);
}
};
//} // namespace detail
template<class Archive, class T>
inline void split_free(
+204
View File
@@ -0,0 +1,204 @@
#ifndef BOOST_SERIALIZATION_STD_VARIANT_HPP
#define BOOST_SERIALIZATION_STD_VARIANT_HPP
// MS compatible compilers support #pragma once
#if defined(_MSC_VER)
# pragma once
#endif
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// variant.hpp - non-intrusive serialization of variant types
//
// copyright (c) 2019 Samuel Debionne, ESRF
//
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org for updates, documentation, and revision history.
//
// Widely inspired form boost::variant serialization
//
#include <boost/serialization/throw_exception.hpp>
#include <variant>
#include <boost/archive/archive_exception.hpp>
#include <boost/serialization/split_free.hpp>
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/nvp.hpp>
namespace boost {
namespace serialization {
template<class Archive>
struct std_variant_save_visitor
{
std_variant_save_visitor(Archive& ar) :
m_ar(ar)
{}
template<class T>
void operator()(T const & value) const
{
m_ar << BOOST_SERIALIZATION_NVP(value);
}
private:
Archive & m_ar;
};
template<class Archive>
struct std_variant_load_visitor
{
std_variant_load_visitor(Archive& ar) :
m_ar(ar)
{}
template<class T>
void operator()(T & value) const
{
m_ar >> BOOST_SERIALIZATION_NVP(value);
}
private:
Archive & m_ar;
};
template<class Archive, class ...Types>
void save(
Archive & ar,
std::variant<Types...> const & v,
unsigned int /*version*/
){
const std::size_t which = v.index();
ar << BOOST_SERIALIZATION_NVP(which);
std_variant_save_visitor<Archive> visitor(ar);
std::visit(visitor, v);
}
// Minimalist metaprogramming for handling parameter pack
namespace mp {
namespace detail {
template <typename Seq>
struct front_impl;
template <template <typename...> class Seq, typename T, typename... Ts>
struct front_impl<Seq<T, Ts...>> {
using type = T;
};
template <typename Seq>
struct pop_front_impl;
template <template <typename...> class Seq, typename T, typename... Ts>
struct pop_front_impl<Seq<T, Ts...>> {
using type = Seq<Ts...>;
};
} //namespace detail
template <typename... Ts>
struct typelist {};
template <typename Seq>
using front = typename detail::front_impl<Seq>::type;
template <typename Seq>
using pop_front = typename detail::pop_front_impl<Seq>::type;
} // namespace mp
template<std::size_t N, class Seq>
struct variant_impl
{
template<class Archive, class V>
static void load (
Archive & ar,
std::size_t which,
V & v,
const unsigned int version
){
if(which == 0){
// note: A non-intrusive implementation (such as this one)
// necessary has to copy the value. This wouldn't be necessary
// with an implementation that de-serialized to the address of the
// aligned storage included in the variant.
using type = mp::front<Seq>;
type value;
ar >> BOOST_SERIALIZATION_NVP(value);
v = std::move(value);
type * new_address = & std::get<type>(v);
ar.reset_object_address(new_address, & value);
return;
}
//typedef typename mpl::pop_front<S>::type type;
using types = mp::pop_front<Seq>;
variant_impl<N - 1, types>::load(ar, which - 1, v, version);
}
};
template<class Seq>
struct variant_impl<0, Seq>
{
template<class Archive, class V>
static void load (
Archive & /*ar*/,
std::size_t /*which*/,
V & /*v*/,
const unsigned int /*version*/
){}
};
template<class Archive, class... Types>
void load(
Archive & ar,
std::variant<Types...>& v,
const unsigned int version
){
std::size_t which;
ar >> BOOST_SERIALIZATION_NVP(which);
if(which >= sizeof...(Types))
// this might happen if a type was removed from the list of variant types
boost::serialization::throw_exception(
boost::archive::archive_exception(
boost::archive::archive_exception::unsupported_version
)
);
variant_impl<sizeof...(Types), mp::typelist<Types...>>::load(ar, which, v, version);
}
template<class Archive,class... Types>
inline void serialize(
Archive & ar,
std::variant<Types...> & v,
const unsigned int file_version
){
split_free(ar,v,file_version);
}
// Specialization for std::monostate
template<class Archive>
void serialize(Archive &, std::monostate &, const unsigned int /*version*/)
{}
} // namespace serialization
} // namespace boost
//template<typename T0_, BOOST_VARIANT_ENUM_SHIFTED_PARAMS(typename T)>
#include <boost/serialization/tracking.hpp>
namespace boost {
namespace serialization {
template<class... Types>
struct tracking_level<
std::variant<Types...>
>{
typedef mpl::integral_c_tag tag;
typedef mpl::int_< ::boost::serialization::track_always> type;
BOOST_STATIC_CONSTANT(int, value = type::value);
};
} // namespace serialization
} // namespace boost
#endif //BOOST_SERIALIZATION_VARIANT_HPP
+159 -22
View File
@@ -13,6 +13,12 @@
// troy d. straszheim <troy@resophonic.com>
// http://www.resophonic.com
//
// copyright (c) 2019 Samuel Debionne, ESRF
//
// copyright (c) 2023
// Robert Ramey <ramey@rrsd.com>
// http://www.rrsd.com
//
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
@@ -31,7 +37,19 @@
#include <boost/serialization/throw_exception.hpp>
#include <boost/variant.hpp>
// Boost Variant supports all C++ versions back to C++03
#include <boost/variant/variant.hpp>
#include <boost/variant/get.hpp>
// Boost Variant2 supports all C++ versions back to C++11
#if BOOST_CXX_VERSION >= 201103L
#include <boost/variant2/variant.hpp>
#endif
// std::variant supports all C++ versions back to C++11
#ifndef BOOST_NO_CXX17_HDR_VARIANT
#include <variant>
#endif
#include <boost/archive/archive_exception.hpp>
@@ -39,19 +57,35 @@
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/nvp.hpp>
// use visitor from boost::variant
template<class Visitor, BOOST_VARIANT_ENUM_PARAMS(class T)>
typename Visitor::result_type visit(
Visitor visitor,
const boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> & t
){
return boost::apply_visitor(visitor, t);
}
template<class Visitor, BOOST_VARIANT_ENUM_PARAMS(class T)>
typename Visitor::result_type visit(
Visitor visitor,
const boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> & t,
const boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> & u
){
return boost::apply_visitor(visitor, t, u);
}
namespace boost {
namespace serialization {
template<class Archive>
struct variant_save_visitor :
boost::static_visitor<>
boost::static_visitor<void>
{
variant_save_visitor(Archive& ar) :
m_ar(ar)
{}
template<class T>
void operator()(T const & value) const
{
void operator()(T const & value) const {
m_ar << BOOST_SERIALIZATION_NVP(value);
}
private:
@@ -67,9 +101,37 @@ void save(
int which = v.which();
ar << BOOST_SERIALIZATION_NVP(which);
variant_save_visitor<Archive> visitor(ar);
v.apply_visitor(visitor);
visit(visitor, v);
}
#if BOOST_CXX_VERSION >= 201103L
template<class Archive, class ...Types>
void save(
Archive & ar,
boost::variant2::variant<Types...> const & v,
unsigned int /*version*/
){
int which = v.index();
ar << BOOST_SERIALIZATION_NVP(which);
const variant_save_visitor<Archive> visitor(ar);
visit(visitor, v);
}
#endif
#ifndef BOOST_NO_CXX17_HDR_VARIANT
template<class Archive, class ...Types>
void save(
Archive & ar,
std::variant<Types...> const & v,
unsigned int /*version*/
){
int which = v.index();
ar << BOOST_SERIALIZATION_NVP(which);
const variant_save_visitor<Archive> visitor(ar);
visit(visitor, v);
}
#endif
template<class S>
struct variant_impl {
@@ -77,17 +139,17 @@ struct variant_impl {
template<class Archive, class V>
static void invoke(
Archive & /*ar*/,
int /*which*/,
std::size_t /*which*/,
V & /*v*/,
const unsigned int /*version*/
){}
};
struct load_impl {
struct load_member {
template<class Archive, class V>
static void invoke(
Archive & ar,
int which,
std::size_t which,
V & v,
const unsigned int version
){
@@ -99,31 +161,30 @@ struct variant_impl {
typedef typename mpl::front<S>::type head_type;
head_type value;
ar >> BOOST_SERIALIZATION_NVP(value);
v = value;
head_type * new_address = & boost::get<head_type>(v);
v = std::move(value);;
head_type * new_address = & get<head_type>(v);
ar.reset_object_address(new_address, & value);
return;
}
typedef typename mpl::pop_front<S>::type type;
variant_impl<type>::load(ar, which - 1, v, version);
variant_impl<type>::load_impl(ar, which - 1, v, version);
}
};
template<class Archive, class V>
static void load(
static void load_impl(
Archive & ar,
int which,
std::size_t which,
V & v,
const unsigned int version
){
typedef typename mpl::eval_if<mpl::empty<S>,
mpl::identity<load_null>,
mpl::identity<load_impl>
mpl::identity<load_member>
>::type typex;
typex::invoke(ar, which, v, version);
}
};
}; // variant_impl
template<class Archive, BOOST_VARIANT_ENUM_PARAMS(/* typename */ class T)>
void load(
@@ -134,34 +195,99 @@ void load(
int which;
typedef typename boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types types;
ar >> BOOST_SERIALIZATION_NVP(which);
if(which >= mpl::size<types>::value)
if(which >= mpl::size<types>::value){
// this might happen if a type was removed from the list of variant types
boost::serialization::throw_exception(
boost::archive::archive_exception(
boost::archive::archive_exception::unsupported_version
)
);
variant_impl<types>::load(ar, which, v, version);
}
variant_impl<types>::load_impl(ar, which, v, version);
}
#if BOOST_CXX_VERSION >= 201103L
template<class Archive, class ... Types>
void load(
Archive & ar,
boost::variant2::variant<Types...> & v,
const unsigned int version
){
int which;
typedef typename boost::variant<Types...>::types types;
ar >> BOOST_SERIALIZATION_NVP(which);
if(which >= sizeof...(Types)){
// this might happen if a type was removed from the list of variant types
boost::serialization::throw_exception(
boost::archive::archive_exception(
boost::archive::archive_exception::unsupported_version
)
);
}
variant_impl<types>::load_impl(ar, which, v, version);
}
#endif
#ifndef BOOST_NO_CXX17_HDR_VARIANT
template<class Archive, class ... Types>
void load(
Archive & ar,
std::variant<Types...> & v,
const unsigned int version
){
int which;
typedef typename boost::variant<Types...>::types types;
ar >> BOOST_SERIALIZATION_NVP(which);
if(which >= sizeof...(Types)){
// this might happen if a type was removed from the list of variant types
boost::serialization::throw_exception(
boost::archive::archive_exception(
boost::archive::archive_exception::unsupported_version
)
);
}
variant_impl<types>::load_impl(ar, which, v, version);
}
#endif
template<class Archive,BOOST_VARIANT_ENUM_PARAMS(/* typename */ class T)>
inline void serialize(
Archive & ar,
boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> & v,
const unsigned int file_version
){
split_free(ar,v,file_version);
boost::serialization::split_free(ar,v,file_version);
}
#if BOOST_CXX_VERSION >= 201103L
template<class Archive, class ... Types>
inline void serialize(
Archive & ar,
boost::variant2::variant<Types...> & v,
const unsigned int file_version
){
boost::serialization::split_free(ar,v,file_version);
}
#endif
#ifndef BOOST_NO_CXX17_HDR_VARIANT
template<class Archive, class ... Types>
inline void serialize(
Archive & ar,
std::variant<Types...> & v,
const unsigned int file_version
){
boost::serialization::split_free(ar,v,file_version);
}
#endif
} // namespace serialization
} // namespace boost
//template<typename T0_, BOOST_VARIANT_ENUM_SHIFTED_PARAMS(typename T)>
#include <boost/serialization/tracking.hpp>
namespace boost {
namespace serialization {
namespace serialization {
template<BOOST_VARIANT_ENUM_PARAMS(/* typename */ class T)>
struct tracking_level<
@@ -172,6 +298,17 @@ struct tracking_level<
BOOST_STATIC_CONSTANT(int, value = type::value);
};
#ifndef BOOST_NO_CXX17_HDR_VARIANT
template<class... Types>
struct tracking_level<
std::variant<Types...>
>{
typedef mpl::integral_c_tag tag;
typedef mpl::int_< ::boost::serialization::track_always> type;
BOOST_STATIC_CONSTANT(int, value = type::value);
};
#endif
} // namespace serialization
} // namespace boost
+174
View File
@@ -0,0 +1,174 @@
#ifndef BOOST_SERIALIZATION_VARIANT2_HPP
#define BOOST_SERIALIZATION_VARIANT2_HPP
// MS compatible compilers support #pragma once
#if defined(_MSC_VER)
# pragma once
#endif
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// variant2.hpp - non-intrusive serialization of variant types
//
// copyright (c) 2019 Samuel Debionne, ESRF
//
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org for updates, documentation, and revision history.
//
// Widely inspired from boost::variant serialization
//
#include <boost/serialization/throw_exception.hpp>
#include <boost/archive/archive_exception.hpp>
#include <boost/mp11/list.hpp>
#include <boost/serialization/split_free.hpp>
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/nvp.hpp>
namespace boost {
namespace serialization {
template<class Archive>
struct variant2_save_visitor
{
variant2_save_visitor(Archive& ar) :
m_ar(ar)
{}
template<class T>
void operator()(T const & value) const
{
m_ar << BOOST_SERIALIZATION_NVP(value);
}
private:
Archive & m_ar;
};
template<class Archive>
struct variant2_load_visitor
{
variant2_load_visitor(Archive& ar) :
m_ar(ar)
{}
template<class T>
void operator()(T & value) const
{
m_ar >> BOOST_SERIALIZATION_NVP(value);
}
private:
Archive & m_ar;
};
template<class Archive, class ...Types>
void save(
Archive & ar,
variant2::variant<Types...> const & v,
unsigned int /*version*/
){
const std::size_t which = v.index();
ar << BOOST_SERIALIZATION_NVP(which);
variant2_save_visitor<Archive> visitor(ar);
std::visit(visitor, v);
}
template<class Seq>
struct variant_impl
{
template<class Archive, class V>
static void load (
Archive & ar,
std::size_t which,
V & v,
const unsigned int version
){
if(which == 0){
// note: A non-intrusive implementation (such as this one)
// necessary has to copy the value. This wouldn't be necessary
// with an implementation that de-serialized to the address of the
// aligned storage included in the variant.
using type = mp11::mp_front<Seq>;
type value;
ar >> BOOST_SERIALIZATION_NVP(value);
v = std::move(value);
type * new_address = & variant2::get<type>(v);
ar.reset_object_address(new_address, & value);
return;
}
//typedef typename mpl::pop_front<S>::type type;
using types = mp11::mp_pop_front<Seq>;
variant_impl<types>::load(ar, which - 1, v, version);
}
};
template<class Seq>
struct variant_impl<Seq>
{
template<class Archive, class V>
static void load (
Archive & /*ar*/,
std::size_t /*which*/,
V & /*v*/,
const unsigned int /*version*/
){}
};
template<class Archive, class... Types>
void load(
Archive & ar,
variant2::variant<Types...> & v,
const unsigned int version
){
std::size_t which;
ar >> BOOST_SERIALIZATION_NVP(which);
if(which >= sizeof...(Types))
// this might happen if a type was removed from the list of variant types
boost::serialization::throw_exception(
boost::archive::archive_exception(
boost::archive::archive_exception::unsupported_version
)
);
variant_impl<sizeof...(Types), mp11::mp_list<Types...>>::load(ar, which, v, version);
}
template<class Archive,class... Types>
inline void serialize(
Archive & ar,
variant2::variant<Types...> & v,
const unsigned int file_version
){
split_free(ar,v,file_version);
}
// Specialization for std::monostate
template<class Archive>
void serialize(Archive &ar, variant2::monostate &, const unsigned int /*version*/)
{}
} // namespace serialization
} // namespace boost
//template<typename T0_, BOOST_VARIANT_ENUM_SHIFTED_PARAMS(typename T)>
#include <boost/serialization/tracking.hpp>
namespace boost {
namespace serialization {
template<class... Types>
struct tracking_level<
variant2::variant<Types...>
>{
typedef mpl::integral_c_tag tag;
typedef mpl::int_< ::boost::serialization::track_always> type;
BOOST_STATIC_CONSTANT(int, value = type::value);
};
} // namespace serialization
} // namespace boost
#endif //BOOST_SERIALIZATION_VARIANT2_HPP
+2 -2
View File
@@ -15,8 +15,8 @@ then
echo " threading=single,multi"
echo " -sBOOST_ARCHIVE_LIST=<archive name>"
else
bjam --dump-tests variant=profile preserve-test-targets=on $@ >bjam.log 2>&1
process_jam_log --v2 <bjam.log
b2 --dump-tests variant=profile preserve-test-targets=on $@ >b2.log 2>&1
process_jam_log --v2 <b2ls.log
# for each test directory
+4 -4
View File
@@ -262,11 +262,11 @@ basic_oarchive_impl::save_object(
}
// we're not tracking this type of object
if(! bos.tracking(m_flags)){
if(! co.m_bos_ptr->tracking(m_flags)){
// just windup the preamble - no object id to write
ar.end_preamble();
// and save the data
(bos.save_object_data)(ar, t);
(co.m_bos_ptr->save_object_data)(ar, t);
return;
}
@@ -284,7 +284,7 @@ basic_oarchive_impl::save_object(
ar.vsave(oid);
ar.end_preamble();
// and data
(bos.save_object_data)(ar, t);
(co.m_bos_ptr->save_object_data)(ar, t);
return;
}
@@ -353,7 +353,7 @@ basic_oarchive_impl::save_pointer(
}
// if we're not tracking
if(! bos.tracking(m_flags)){
if(! co.m_bos_ptr->tracking(m_flags)){
// just save the data itself
ar.end_preamble();
serialization::state_saver<const void *> x(pending_object);
+3 -1
View File
@@ -82,7 +82,9 @@ struct assign_impl<std::string> {
++b;
}
}
//assign_impl(const assign_impl & rhs);
assign_impl(const assign_impl & rhs)
: m_t(rhs.m_t)
{}
assign_impl & operator=(assign_impl & rhs);
assign_impl(std::string & rhs)
: m_t(rhs)
-5
View File
@@ -79,8 +79,6 @@ test-suite "serialization" :
[ test-bsl-run_files test_list_ptrs : A ]
[ test-bsl-run_files test_map : A ]
[ test-bsl-run_files test_map_hashed : A : : [ requires hash ] ] # BOOST_HAS_HASH
[ test-bsl-run_files test_map_unordered : A : : [ requires cxx11_hdr_unordered_map ] ] # BOOST_NO_CXX11_HDR_UNORDERED_MAP
[ test-bsl-run_files test_map_boost_unordered : A ]
[ test-bsl-run_files test_mi ]
[ test-bsl-run_files test_multiple_ptrs : A ]
[ test-bsl-run_files test_multiple_inheritance ]
@@ -99,8 +97,6 @@ test-suite "serialization" :
[ test-bsl-run_files test_registered ]
[ test-bsl-run_files test_set : A ]
[ test-bsl-run_files test_set_hashed : A : : [ requires hash ] ] # BOOST_HAS_HASH
[ test-bsl-run_files test_set_unordered : A : : [ requires cxx11_hdr_unordered_set ] ] # BOOST_NO_CXX11_HDR_UNORDERED_SET
[ test-bsl-run_files test_set_boost_unordered : A ]
[ test-bsl-run_files test_simple_class : A ]
[ test-bsl-run_files test_simple_class_ptr : A ]
[ test-bsl-run_files test_slist : A : : [ requires slist ] ] # BOOST_HAS_SLIST ]
@@ -188,4 +184,3 @@ if ! $(BOOST_ARCHIVE_LIST) {
[ compile test_const_pass.cpp ]
;
}
-1
View File
@@ -1 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <!DOCTYPE boost_serialization> <boost_serialization signature="serialization::archive" version="3"> <a class_id="0" tracking_level="0"> <b>1</b> <f>96953204</f> <g>177129195</g> <l>1</l> <m>5627</m> <n>23010</n> <o>7419</o> <p>16212</p> <q>4086</q> <r>2749</r> <c>-33</c> <s>124</s> <t>28</t> <u>32225</u> <v>17543</v> <w>0.84431422</w> <x>1.0170664757130923</x> <y>tjbx</y> <z>cuwjentqpkejp</z> </a> </boost_serialization>
+3 -2
View File
@@ -21,7 +21,6 @@ namespace std{
#endif
#include "test_tools.hpp"
#include <boost/lexical_cast.hpp>
#include <boost/serialization/split_free.hpp>
#include <boost/serialization/vector.hpp>
#include <string>
@@ -108,7 +107,9 @@ int test_main( int /* argc */, char* /* argv */[] ){
std::vector<my_string> v1;
for(int i=0; i<1000; ++i){
v1.push_back(my_string(boost::lexical_cast<std::string>(i % 100)));
char sbuffer[10];
std::snprintf(sbuffer, sizeof(sbuffer), "%i", i % 100);
v1.push_back(my_string(sbuffer));
}
{
test_ostream os(testfile, TEST_STREAM_FLAGS);
-142
View File
@@ -1,142 +0,0 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// test_map.cpp
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// (C) Copyright 2014 Jim Bell
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// should pass compilation and execution
#include <algorithm> // std::copy
#include <vector>
#include <fstream>
#include <cstddef> // size_t, NULL
#include <boost/config.hpp>
#include <boost/detail/workaround.hpp>
#include <cstdio>
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
using ::rand;
using ::size_t;
}
#endif
#include "test_tools.hpp"
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/map.hpp>
#include "A.hpp"
#include "A.ipp"
///////////////////////////////////////////////////////
// a key value initialized with a random value for use
// in testing STL map serialization
struct random_key {
friend class boost::serialization::access;
template<class Archive>
void serialize(
Archive & ar,
const unsigned int /* file_version */
){
ar & boost::serialization::make_nvp("random_key", m_i);
}
int m_i;
random_key() : m_i(std::rand()){};
bool operator<(const random_key &rhs) const {
return m_i < rhs.m_i;
}
bool operator==(const random_key &rhs) const {
return m_i == rhs.m_i;
}
operator std::size_t () const { // required by hash_map
return m_i;
}
};
#include <boost/serialization/boost_unordered_map.hpp>
#include <functional> // requires changeset [69520]; Ticket #5254
namespace boost {
template<>
struct hash<random_key>{
std::size_t operator()(const random_key& r) const {
return static_cast<std::size_t>(r);
}
};
} // namespace std
void
test_unordered_map(){
const char * testfile = boost::archive::tmpnam(NULL);
BOOST_REQUIRE(NULL != testfile);
BOOST_CHECKPOINT("unordered_map");
// test unordered_map of objects
boost::unordered_map<random_key, A> anunordered_map;
anunordered_map.insert(std::make_pair(random_key(), A()));
anunordered_map.insert(std::make_pair(random_key(), A()));
{
test_ostream os(testfile, TEST_STREAM_FLAGS);
test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
oa << boost::serialization::make_nvp("anunorderedmap",anunordered_map);
}
boost::unordered_map<random_key, A> anunordered_map1;
{
test_istream is(testfile, TEST_STREAM_FLAGS);
test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
ia >> boost::serialization::make_nvp("anunorderedmap",anunordered_map1);
}
std::vector< std::pair<random_key, A> > tvec, tvec1;
std::copy(anunordered_map.begin(), anunordered_map.end(), std::back_inserter(tvec));
std::sort(tvec.begin(), tvec.end());
std::copy(anunordered_map1.begin(), anunordered_map1.end(), std::back_inserter(tvec1));
std::sort(tvec1.begin(), tvec1.end());
BOOST_CHECK(tvec == tvec1);
std::remove(testfile);
}
void
test_unordered_multimap(){
const char * testfile = boost::archive::tmpnam(NULL);
BOOST_REQUIRE(NULL != testfile);
BOOST_CHECKPOINT("unordered_multimap");
boost::unordered_multimap<random_key, A> anunordered_multimap;
anunordered_multimap.insert(std::make_pair(random_key(), A()));
anunordered_multimap.insert(std::make_pair(random_key(), A()));
{
test_ostream os(testfile, TEST_STREAM_FLAGS);
test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
oa << boost::serialization::make_nvp("anunordered_multimap", anunordered_multimap);
}
boost::unordered_multimap<random_key, A> anunordered_multimap1;
{
test_istream is(testfile, TEST_STREAM_FLAGS);
test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
ia >> boost::serialization::make_nvp("anunordered_multimap", anunordered_multimap1);
}
std::vector< std::pair<random_key, A> > tvec, tvec1;
tvec.clear();
tvec1.clear();
std::copy(anunordered_multimap.begin(), anunordered_multimap.end(), std::back_inserter(tvec));
std::sort(tvec.begin(), tvec.end());
std::copy(anunordered_multimap1.begin(), anunordered_multimap1.end(), std::back_inserter(tvec1));
std::sort(tvec1.begin(), tvec1.end());
BOOST_CHECK(tvec == tvec1);
std::remove(testfile);
}
int test_main( int /* argc */, char* /* argv */[] )
{
test_unordered_map();
test_unordered_multimap();
return EXIT_SUCCESS;
}
-142
View File
@@ -1,142 +0,0 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// test_map.cpp
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// (C) Copyright 2014 Jim Bell
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// should pass compilation and execution
#include <algorithm> // std::copy
#include <vector>
#include <fstream>
#include <cstddef> // size_t, NULL
#include <boost/config.hpp>
#include <boost/detail/workaround.hpp>
#include <cstdio>
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
using ::rand;
using ::size_t;
}
#endif
#include "test_tools.hpp"
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/map.hpp>
#include "A.hpp"
#include "A.ipp"
///////////////////////////////////////////////////////
// a key value initialized with a random value for use
// in testing STL map serialization
struct random_key {
friend class boost::serialization::access;
template<class Archive>
void serialize(
Archive & ar,
const unsigned int /* file_version */
){
ar & boost::serialization::make_nvp("random_key", m_i);
}
int m_i;
random_key() : m_i(std::rand()){};
bool operator<(const random_key &rhs) const {
return m_i < rhs.m_i;
}
bool operator==(const random_key &rhs) const {
return m_i == rhs.m_i;
}
operator std::size_t () const { // required by hash_map
return m_i;
}
};
#include <boost/serialization/unordered_map.hpp>
#include <functional> // requires changeset [69520]; Ticket #5254
namespace std {
template<>
struct hash<random_key>{
std::size_t operator()(const random_key& r) const {
return static_cast<std::size_t>(r);
}
};
} // namespace std
void
test_unordered_map(){
const char * testfile = boost::archive::tmpnam(NULL);
BOOST_REQUIRE(NULL != testfile);
BOOST_CHECKPOINT("unordered_map");
// test unordered_map of objects
std::unordered_map<random_key, A> anunordered_map;
anunordered_map.insert(std::make_pair(random_key(), A()));
anunordered_map.insert(std::make_pair(random_key(), A()));
{
test_ostream os(testfile, TEST_STREAM_FLAGS);
test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
oa << boost::serialization::make_nvp("anunorderedmap",anunordered_map);
}
std::unordered_map<random_key, A> anunordered_map1;
{
test_istream is(testfile, TEST_STREAM_FLAGS);
test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
ia >> boost::serialization::make_nvp("anunorderedmap",anunordered_map1);
}
std::vector< std::pair<random_key, A> > tvec, tvec1;
std::copy(anunordered_map.begin(), anunordered_map.end(), std::back_inserter(tvec));
std::sort(tvec.begin(), tvec.end());
std::copy(anunordered_map1.begin(), anunordered_map1.end(), std::back_inserter(tvec1));
std::sort(tvec1.begin(), tvec1.end());
BOOST_CHECK(tvec == tvec1);
std::remove(testfile);
}
void
test_unordered_multimap(){
const char * testfile = boost::archive::tmpnam(NULL);
BOOST_REQUIRE(NULL != testfile);
BOOST_CHECKPOINT("unordered_multimap");
std::unordered_multimap<random_key, A> anunordered_multimap;
anunordered_multimap.insert(std::make_pair(random_key(), A()));
anunordered_multimap.insert(std::make_pair(random_key(), A()));
{
test_ostream os(testfile, TEST_STREAM_FLAGS);
test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
oa << boost::serialization::make_nvp("anunordered_multimap", anunordered_multimap);
}
std::unordered_multimap<random_key, A> anunordered_multimap1;
{
test_istream is(testfile, TEST_STREAM_FLAGS);
test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
ia >> boost::serialization::make_nvp("anunordered_multimap", anunordered_multimap1);
}
std::vector< std::pair<random_key, A> > tvec, tvec1;
tvec.clear();
tvec1.clear();
std::copy(anunordered_multimap.begin(), anunordered_multimap.end(), std::back_inserter(tvec));
std::sort(tvec.begin(), tvec.end());
std::copy(anunordered_multimap1.begin(), anunordered_multimap1.end(), std::back_inserter(tvec1));
std::sort(tvec1.begin(), tvec1.end());
BOOST_CHECK(tvec == tvec1);
std::remove(testfile);
}
int test_main( int /* argc */, char* /* argv */[] )
{
test_unordered_map();
test_unordered_multimap();
return EXIT_SUCCESS;
}
+1 -1
View File
@@ -73,7 +73,7 @@ struct Sub :
Base2(x),
m_x(x)
{}
bool operator==(Sub & rhs) const {
bool operator==(const Sub & rhs) const {
if(! Base2::operator==(rhs))
return false;
if(! Base1::operator==(rhs))
+30 -20
View File
@@ -23,8 +23,6 @@ namespace std{
#include <boost/archive/archive_exception.hpp>
#include "test_tools.hpp"
#include <boost/serialization/optional.hpp>
#include <boost/serialization/string.hpp>
struct A {
int m_x;
@@ -44,18 +42,19 @@ struct A {
{}
};
int test_main( int /* argc */, char* /* argv */[] )
{
// Optional is the class optional implementation you use
template<template<class> class Optional>
int test(){
const char * testfile = boost::archive::tmpnam(NULL);
BOOST_REQUIRE(NULL != testfile);
const boost::optional<int> aoptional1;
const boost::optional<int> aoptional2(123);
const boost::optional<A> aoptional3;
const Optional<int> aoptional1;
const Optional<int> aoptional2(123);
const Optional<A> aoptional3;
A a(1);
const boost::optional<A> aoptional4(a);
const boost::optional<A *> aoptional5;
const boost::optional<A *> aoptional6(& a);
const Optional<A> aoptional4(a);
const Optional<A *> aoptional5;
const Optional<A *> aoptional6(& a);
{
test_ostream os(testfile, TEST_STREAM_FLAGS);
test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
@@ -66,12 +65,12 @@ int test_main( int /* argc */, char* /* argv */[] )
oa << boost::serialization::make_nvp("aoptional5",aoptional5);
oa << boost::serialization::make_nvp("aoptional6",aoptional6);
}
boost::optional<int> aoptional1a(999);
boost::optional<int> aoptional2a;
boost::optional<A> aoptional3a;
boost::optional<A> aoptional4a;
boost::optional<A *> aoptional5a;
boost::optional<A *> aoptional6a;
Optional<int> aoptional1a(999);
Optional<int> aoptional2a;
Optional<A> aoptional3a;
Optional<A> aoptional4a;
Optional<A *> aoptional5a;
Optional<A *> aoptional6a;
{
test_istream is(testfile, TEST_STREAM_FLAGS);
test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
@@ -85,12 +84,23 @@ int test_main( int /* argc */, char* /* argv */[] )
BOOST_CHECK(aoptional1 == aoptional1a);
BOOST_CHECK(aoptional2 == aoptional2a);
BOOST_CHECK(aoptional3 == aoptional3a);
BOOST_CHECK(aoptional4.get() == aoptional4a.get());
BOOST_CHECK(aoptional5 == aoptional5a);
BOOST_CHECK(*aoptional6.get() == *aoptional6a.get());
BOOST_CHECK(aoptional4 == aoptional4a);
BOOST_CHECK(aoptional5 == aoptional5a); // not initialized
BOOST_CHECK(**aoptional6 == **aoptional6a);
std::remove(testfile);
return EXIT_SUCCESS;
}
// EOF
#include <boost/serialization/optional.hpp>
#ifndef BOOST_NO_CXX17_HDR_OPTIONAL
#include <optional>
#endif
int test_main( int /* argc */, char* /* argv */[] ){
test<boost::optional>();
#ifndef BOOST_NO_CXX17_HDR_OPTIONAL
test<std::optional>();
#endif
return EXIT_SUCCESS;
}
+3 -2
View File
@@ -33,7 +33,6 @@ namespace std{
#include <vector>
#include "test_tools.hpp"
#include <boost/lexical_cast.hpp>
#include <boost/serialization/split_free.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/nvp.hpp>
@@ -121,7 +120,9 @@ int test_main(int /* argc */, char * /* argv */ [])
std::vector<my_string> v1;
for(int i=0; i<1000; ++i){
v1.push_back(my_string(boost::lexical_cast<std::string>(i % 100)));
char sbuffer[10];
std::snprintf(sbuffer, sizeof(sbuffer), "%i", i % 100);
v1.push_back(my_string(sbuffer));
}
// test using using polymorphic implementation.
-123
View File
@@ -1,123 +0,0 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// test_set.cpp
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// (C) Copyright 2014 Jim Bell
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// should pass compilation and execution
#include <cstddef> // NULLsize_t
#include <cstdio> // remove
#include <fstream>
#include <algorithm> // std::copy
#include <vector>
#include <boost/config.hpp>
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
using ::size_t;
}
#endif
#include <boost/detail/workaround.hpp>
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
using ::remove;
}
#endif
#include <boost/archive/archive_exception.hpp>
#include "test_tools.hpp"
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/set.hpp>
#include "A.hpp"
#include "A.ipp"
#include <boost/serialization/boost_unordered_set.hpp>
#include <functional> // requires changeset [69520]; Ticket #5254
namespace boost {
template<>
struct hash<A> {
std::size_t operator()(const A& a) const {
return static_cast<std::size_t>(a);
}
};
} // namespace boost
void
test_unordered_set(){
const char * testfile = boost::archive::tmpnam(NULL);
BOOST_REQUIRE(NULL != testfile);
// test array of objects
boost::unordered_set<A> anunordered_set;
A a, a1;
anunordered_set.insert(a);
anunordered_set.insert(a1);
{
test_ostream os(testfile, TEST_STREAM_FLAGS);
test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
oa << boost::serialization::make_nvp("anunordered_set", anunordered_set);
}
boost::unordered_set<A> anunordered_set1;
{
test_istream is(testfile, TEST_STREAM_FLAGS);
test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
ia >> boost::serialization::make_nvp("anunordered_set", anunordered_set1);
}
std::vector<A> tvec, tvec1;
tvec.clear();
tvec1.clear();
std::copy(anunordered_set.begin(), anunordered_set.end(), std::back_inserter(tvec));
std::sort(tvec.begin(), tvec.end());
std::copy(anunordered_set1.begin(), anunordered_set1.end(), std::back_inserter(tvec1));
std::sort(tvec1.begin(), tvec1.end());
BOOST_CHECK(tvec == tvec1);
std::remove(testfile);
}
void
test_unordered_multiset(){
const char * testfile = boost::archive::tmpnam(NULL);
BOOST_REQUIRE(NULL != testfile);
boost::unordered_multiset<A> anunordered_multiset;
anunordered_multiset.insert(A());
anunordered_multiset.insert(A());
{
test_ostream os(testfile, TEST_STREAM_FLAGS);
test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
oa << boost::serialization::make_nvp("anunordered_multiset", anunordered_multiset);
}
boost::unordered_multiset<A> anunordered_multiset1;
{
test_istream is(testfile, TEST_STREAM_FLAGS);
test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
ia >> boost::serialization::make_nvp("anunordered_multiset", anunordered_multiset1);
}
std::vector<A> tvec, tvec1;
tvec.clear();
tvec1.clear();
std::copy(anunordered_multiset.begin(), anunordered_multiset.end(), std::back_inserter(tvec));
std::sort(tvec.begin(), tvec.end());
std::copy(anunordered_multiset1.begin(), anunordered_multiset1.end(), std::back_inserter(tvec1));
std::sort(tvec1.begin(), tvec1.end());
BOOST_CHECK(tvec == tvec1);
std::remove(testfile);
}
int test_main( int /* argc */, char* /* argv */[] ){
test_unordered_set();
test_unordered_multiset();
return EXIT_SUCCESS;
}
-123
View File
@@ -1,123 +0,0 @@
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// test_set.cpp
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// (C) Copyright 2014 Jim Bell
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// should pass compilation and execution
#include <cstddef> // NULLsize_t
#include <cstdio> // remove
#include <fstream>
#include <algorithm> // std::copy
#include <vector>
#include <boost/config.hpp>
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
using ::size_t;
}
#endif
#include <boost/detail/workaround.hpp>
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
using ::remove;
}
#endif
#include <boost/archive/archive_exception.hpp>
#include "test_tools.hpp"
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/set.hpp>
#include "A.hpp"
#include "A.ipp"
#include <boost/serialization/unordered_set.hpp>
#include <functional> // requires changeset [69520]; Ticket #5254
namespace std {
template<>
struct hash<A> {
std::size_t operator()(const A& a) const {
return static_cast<std::size_t>(a);
}
};
} // namespace std
void
test_unordered_set(){
const char * testfile = boost::archive::tmpnam(NULL);
BOOST_REQUIRE(NULL != testfile);
// test array of objects
std::unordered_set<A> anunordered_set;
A a, a1;
anunordered_set.insert(a);
anunordered_set.insert(a1);
{
test_ostream os(testfile, TEST_STREAM_FLAGS);
test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
oa << boost::serialization::make_nvp("anunordered_set", anunordered_set);
}
std::unordered_set<A> anunordered_set1;
{
test_istream is(testfile, TEST_STREAM_FLAGS);
test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
ia >> boost::serialization::make_nvp("anunordered_set", anunordered_set1);
}
std::vector<A> tvec, tvec1;
tvec.clear();
tvec1.clear();
std::copy(anunordered_set.begin(), anunordered_set.end(), std::back_inserter(tvec));
std::sort(tvec.begin(), tvec.end());
std::copy(anunordered_set1.begin(), anunordered_set1.end(), std::back_inserter(tvec1));
std::sort(tvec1.begin(), tvec1.end());
BOOST_CHECK(tvec == tvec1);
std::remove(testfile);
}
void
test_unordered_multiset(){
const char * testfile = boost::archive::tmpnam(NULL);
BOOST_REQUIRE(NULL != testfile);
std::unordered_multiset<A> anunordered_multiset;
anunordered_multiset.insert(A());
anunordered_multiset.insert(A());
{
test_ostream os(testfile, TEST_STREAM_FLAGS);
test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
oa << boost::serialization::make_nvp("anunordered_multiset", anunordered_multiset);
}
std::unordered_multiset<A> anunordered_multiset1;
{
test_istream is(testfile, TEST_STREAM_FLAGS);
test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
ia >> boost::serialization::make_nvp("anunordered_multiset", anunordered_multiset1);
}
std::vector<A> tvec, tvec1;
tvec.clear();
tvec1.clear();
std::copy(anunordered_multiset.begin(), anunordered_multiset.end(), std::back_inserter(tvec));
std::sort(tvec.begin(), tvec.end());
std::copy(anunordered_multiset1.begin(), anunordered_multiset1.end(), std::back_inserter(tvec1));
std::sort(tvec1.begin(), tvec1.end());
BOOST_CHECK(tvec == tvec1);
std::remove(testfile);
}
int test_main( int /* argc */, char* /* argv */[] ){
test_unordered_set();
test_unordered_multiset();
return EXIT_SUCCESS;
}
+101 -195
View File
@@ -6,6 +6,10 @@
// troy d. straszheim <troy@resophonic.com>
// http://www.resophonic.com
//
// copyright (c) 2023
// Robert Ramey <ramey@rrsd.com>
// http://www.rrsd.com
//
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
@@ -25,7 +29,7 @@
#endif
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
namespace std {
using ::remove;
}
#endif
@@ -33,7 +37,6 @@ namespace std{
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/serialization/throw_exception.hpp>
#if defined(_MSC_VER) && (_MSC_VER <= 1020)
# pragma warning (disable : 4786) // too long name, harmless warning
@@ -42,9 +45,14 @@ namespace std{
#include "test_tools.hpp"
#include <boost/archive/archive_exception.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/variant.hpp>
#include <boost/serialization/throw_exception.hpp>
#include <boost/variant/static_visitor.hpp>
namespace boost {
template<typename ResultType> class static_visitor;
}
#include "A.hpp"
#include "A.ipp"
@@ -53,6 +61,7 @@ class are_equal
: public boost::static_visitor<bool>
{
public:
typedef bool result_type;
// note extra rigamarole for compilers which don't support
// partial function template ordering - specifically msvc 6.x
struct same {
@@ -79,6 +88,12 @@ public:
return type::invoke(t, u);
}
template <class T, class U>
bool operator()(T * const & t, U * const & u) const
{
return this->operator()(*t, *u);
}
bool operator()( const float & lhs, const float & rhs ) const
{
#if BOOST_CXX_VERSION > 199711L // only include floating point if C++ version >= C++11
@@ -97,215 +112,106 @@ public:
}
};
template <class T>
void test_type(const T& gets_written){
const char * testfile = boost::archive::tmpnam(NULL);
BOOST_REQUIRE(testfile != NULL);
{
test_ostream os(testfile, TEST_STREAM_FLAGS);
test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
oa << boost::serialization::make_nvp("written", gets_written);
}
T got_read;
{
test_istream is(testfile, TEST_STREAM_FLAGS);
test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
ia >> boost::serialization::make_nvp("written", got_read);
}
BOOST_CHECK(boost::apply_visitor(are_equal(), gets_written, got_read));
std::remove(testfile);
}
// this verifies that if you try to read in a variant from a file
// whose "which" is illegal for the one in memory (that is, you're
// reading in to a different variant than you wrote out to) the load()
// operation will throw. One could conceivably add checking for
// sequence length as well, but this would add size to the archive for
// dubious benefit.
//
void do_bad_read()
{
// Compiling this test invokes and ICE on msvc 6
// So, we'll just to skip it for this compiler
#if defined(_MSC_VER) && (_MSC_VER <= 1020)
boost::variant<bool, float, int, std::string> big_variant;
big_variant = std::string("adrenochrome");
const char * testfile = boost::archive::tmpnam(NULL);
BOOST_REQUIRE(testfile != NULL);
{
test_ostream os(testfile, TEST_STREAM_FLAGS);
test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
oa << BOOST_SERIALIZATION_NVP(big_variant);
}
boost::variant<bool, float, int> little_variant;
{
test_istream is(testfile, TEST_STREAM_FLAGS);
test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
bool exception_invoked = false;
BOOST_TRY {
ia >> BOOST_SERIALIZATION_NVP(little_variant);
} BOOST_CATCH (boost::archive::archive_exception const& e) {
BOOST_CHECK(boost::archive::archive_exception::unsupported_version == e.code);
exception_invoked = true;
}
BOOST_CATCH_END
BOOST_CHECK(exception_invoked);
}
#endif
}
struct H {
int i;
};
namespace boost {
namespace serialization {
template<class Archive>
void serialize(Archive &ar, H & h, const unsigned int /*file_version*/){
ar & boost::serialization::make_nvp("h", h.i);
}
} // namespace serialization
} // namespace boost
inline bool operator==(H const & lhs, H const & rhs) {
return lhs.i == rhs.i;
}
inline bool operator!=(H const & lhs, H const & rhs) {
return !(lhs == rhs);
}
inline bool operator<(H const & lhs, H const & rhs) {
return lhs.i < rhs.i;
}
inline std::size_t hash_value(H const & val) {
return val.i;
}
void test_pointer(){
template<class Variant>
bool test_type(const Variant & v){
const char * testfile = boost::archive::tmpnam(NULL);
BOOST_REQUIRE(testfile != NULL);
typedef boost::variant<H, int> variant_t;
H const h = {5};
variant_t v(h);
{
test_ostream os(testfile, TEST_STREAM_FLAGS);
test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
oa << boost::serialization::make_nvp("written", v);
const H * h_ptr = & boost::strict_get<H const &>(v);
oa << boost::serialization::make_nvp("written", h_ptr);
}
variant_t v2;
Variant vx;
{
test_istream is(testfile, TEST_STREAM_FLAGS);
test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
ia >> boost::serialization::make_nvp("written", v2);
H * h2_ptr;
ia >> boost::serialization::make_nvp("written", h2_ptr);
BOOST_CHECK_EQUAL(h, boost::strict_get<H const>(v2));
BOOST_CHECK_EQUAL(h2_ptr, & boost::strict_get<H const &>(v2));
BOOST_TRY {
ia >> boost::serialization::make_nvp("written", vx);
BOOST_CHECK(visit(are_equal(), v, vx));
}
BOOST_CATCH(boost::archive::archive_exception const& e) {
return false;
}
BOOST_CATCH_END
}
BOOST_CHECK_EQUAL(v, v2);
std::remove(testfile);
return true;
}
#include <boost/serialization/map.hpp>
#include <boost/serialization/set.hpp>
// test a pointer to an object contained into a variant that is an
// element of a set
void test_variant_set()
template<class Variant>
void test(Variant & v)
{
const char * testfile = boost::archive::tmpnam(NULL);
BOOST_REQUIRE(testfile != NULL);
typedef boost::variant<H, int> variant_t;
typedef std::set<variant_t> uset_t;
uset_t set;
{
test_ostream os(testfile, TEST_STREAM_FLAGS);
test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
H const h = {5};
variant_t v(h);
set.insert(v);
oa << boost::serialization::make_nvp("written", set);
H const * const h_ptr = boost::strict_get<H const>(&(*set.begin()));
oa << boost::serialization::make_nvp("written", h_ptr);
}
uset_t set2;
{
test_istream is(testfile, TEST_STREAM_FLAGS);
test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
ia >> boost::serialization::make_nvp("written", set2);
H * h_ptr;
ia >> boost::serialization::make_nvp("written", h_ptr);
const H * h_ptr2 = & boost::strict_get<H const>(*set2.begin());
BOOST_CHECK_EQUAL(h_ptr, h_ptr2);
}
BOOST_CHECK_EQUAL(set, set2);
// uninitialized
test_type(v);
v = false;
test_type(v);
v = 1;
test_type(v);
v = (float) 2.3;
test_type(v);
v = (double) 6.4;
test_type(v);
v = A();
test_type(v);
v = std::string("we can't stop here, this is Bat Country");
test_type(v);
}
// test a pointer to an object contained into a variant that is an
// element of a map
void test_variant_map()
{
const char * testfile = boost::archive::tmpnam(NULL);
BOOST_REQUIRE(testfile != NULL);
typedef boost::variant<H, int> variant_t;
typedef std::map<int, variant_t> map_t;
map_t map;
{
test_ostream os(testfile, TEST_STREAM_FLAGS);
test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
H const h = {5};
variant_t v(h);
map[0] = v;
BOOST_ASSERT(1 == map.size());
oa << boost::serialization::make_nvp("written", map);
H const * const h_ptr = boost::strict_get<H const>(&map[0]);
BOOST_CHECK_EQUAL(h_ptr, boost::strict_get<H const>(&map[0]));
oa << boost::serialization::make_nvp("written", h_ptr);
}
map_t map2;
{
test_istream is(testfile, TEST_STREAM_FLAGS);
test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
ia >> boost::serialization::make_nvp("written", map2);
BOOST_ASSERT(1 == map2.size());
H * h_ptr;
ia >> boost::serialization::make_nvp("written", h_ptr);
H const * const h_ptr2 = boost::strict_get<H const>(&map2[0]);
BOOST_CHECK_EQUAL(h_ptr, h_ptr2);
}
BOOST_CHECK_EQUAL(map, map2);
}
#include <boost/serialization/variant.hpp>
int test_main( int /* argc */, char* /* argv */[] )
{
{
boost::variant<bool, int, float, double, A, std::string> v;
v = false;
test_type(v);
v = 1;
test_type(v);
v = (float) 2.3;
test_type(v);
v = (double) 6.4;
test_type(v);
v = std::string("we can't stop here, this is Bat Country");
test_type(v);
v = A();
test_type(v);
}
test_pointer();
test_variant_set();
test_variant_map();
do_bad_read();
#include <boost/variant/variant.hpp>
#include <cstdio>
int test_boost_variant(){
std::cerr << "Testing boost_variant\n";
boost::variant<bool, int, float, double, A, std::string> v;
test(v);
const A a;
boost::variant<bool, int, float, double, const A *, std::string> v1 = & a;
test_type(v1);
return EXIT_SUCCESS;
}
// boost::variant2/variant requires C++ 11
#if BOOST_CXX_VERSION >= 201103L
#include <boost/variant2/variant.hpp>
int test_boost_variant2(){
std::cerr << "Testing boost_variant2\n";
boost::variant2::variant<bool, int, float, double, A, std::string> v;
test(v);
const A a;
boost::variant2::variant<bool, int, float, double, const A *, std::string> v1 = & a;
test_type(v1);
return EXIT_SUCCESS;
}
#endif
// std::variant reqires C++ 17 or more
#ifndef BOOST_NO_CXX17_HDR_VARIANT
#include <variant>
int test_std_variant(){
std::cerr << "Testing Std Variant\n";
std::variant<bool, int, float, double, A, std::string> v;
test(v);
const A a;
std::variant<bool, int, float, double, const A *, std::string> v1 = & a;
test_type(v1);
return EXIT_SUCCESS;
}
#endif
int test_main( int /* argc */, char* /* argv */[] ){
return test_boost_variant()
#if BOOST_CXX_VERSION >= 201103L
|| test_boost_variant2()
#endif
#ifndef BOOST_NO_CXX17_HDR_VARIANT
|| test_std_variant()
#endif
;
}
// EOF
-3
View File
@@ -52,9 +52,6 @@ rule run-template ( test-name : sources * : files * : requirements * ) {
<toolset>msvc:<cxxflags>"-wd4996"
<toolset>clang:<variant>debug:<cxxflags>"-fsanitize=memory"
# toolset optimizations
<toolset>gcc:<cxxflags>"-ftemplate-depth-255"
<toolset>clang:<cxxflags>"-ftemplate-depth-255"
<toolset>darwin:<cxxflags>"-ftemplate-depth-255"
<toolset>msvc:<cxxflags>"-Gy"
# linking
<link>shared:<define>BOOST_SERIALIZATION_DYN_LINK=1