-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathserializer.h
3282 lines (2949 loc) · 87.6 KB
/
serializer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef ZPP_SERIALIZER_H
#define ZPP_SERIALIZER_H
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <initializer_list>
#include <memory>
#include <new>
#include <stdexcept>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
#if __cplusplus >= 201703L
#include <optional>
#include <variant>
#endif
#ifdef ZPP_SERIALIZER_FREESTANDING
#include <string_view>
#else
#include <mutex>
#include <shared_mutex>
#include <unordered_map>
#endif
namespace zpp
{
/**
* Supports serialization of objects and polymorphic objects.
* Example of non polymorphic serialization:
* ~~~
* class point
* {
* public:
* point() = default;
* point(int x, int y) noexcept :
* m_x(x),
* m_y(y)
* {
* }
*
* friend zpp::serializer::access;
* template <typename Archive, typename Self>
* static void serialize(Archive & archive, Self & self)
* {
* archive(self.m_x, self.m_y);
* }
*
* int get_x() const noexcept
* {
* return m_x;
* }
*
* int get_y() const noexcept
* {
* return m_y;
* }
*
* private:
* int m_x = 0;
* int m_y = 0;
* };
*
* static void foo()
* {
* std::vector<unsigned char> data;
* zpp::serializer::memory_input_archive in(data);
* zpp::serializer::memory_output_archive out(data);
*
* out(point(1337, 1338));
*
* point my_point;
* in(my_point);
*
* std::cout << my_point.get_x() << ' ' << my_point.get_y() << '\n';
* }
* ~~~
*
* Example of polymorphic serialization:
* ~~~
* class person : public zpp::serializer::polymorphic
* {
* public:
* person() = default;
* explicit person(std::string name) noexcept :
* m_name(std::move(name))
* {
* }
*
* friend zpp::serializer::access;
* template <typename Archive, typename Self>
* static void serialize(Archive & archive, Self & self)
* {
* archive(self.m_name);
* }
*
* const std::string & get_name() const noexcept
* {
* return m_name;
* }
*
* virtual void print() const
* {
* std::cout << "person: " << m_name;
* }
*
* private:
* std::string m_name;
* };
*
* class student : public person
* {
* public:
* student() = default;
* student(std::string name, std::string university) noexcept :
* person(std::move(name)),
* m_university(std::move(university))
* {
* }
*
* friend zpp::serializer::access;
* template <typename Archive, typename Self>
* static void serialize(Archive & archive, Self & self)
* {
* person::serialize(archive, self);
* archive(self.m_university);
* }
*
* virtual void print() const
* {
* std::cout << "student: " << person::get_name() << ' ' <<
* m_university << '\n';
* }
*
* private:
* std::string m_university;
* };
*
* namespace
* {
* zpp::serializer::register_types<
* zpp::serializer::make_type<person,
* zpp::serializer::make_id("v1::person")>,
* zpp::serializer::make_type<student,
* zpp::serializer::make_id("v1::student")> > _; } // <anynymous namespace>
*
* static void foo()
* {
* std::vector<unsigned char> data;
* zpp::serializer::memory_input_archive in(data);
* zpp::serializer::memory_output_archive out(data);
*
* std::unique_ptr<person> my_person =
* std::make_unique<student>("1337", "1337University"); out(my_person);
*
* my_person = nullptr;
* in(my_person);
*
* my_person->print();
* }
*
* static void bar()
* {
* std::vector<unsigned char> data;
* zpp::serializer::memory_input_archive in(data);
* zpp::serializer::memory_output_archive out(data);
*
* out(zpp::serializer::as_polymorphic(student("1337",
* "1337University")));
*
* std::unique_ptr<person> my_person;
* in(my_person);
*
* my_person->print();
* }
* ~~~
*/
namespace serializer
{
#ifdef ZPP_SERIALIZER_FREESTANDING
namespace freestanding
{
/**
* Returns the error category for a given error code enumeration type,
* using an argument dependent lookup of a user implemented category
* function.
*/
template <typename ErrorCode>
decltype(auto) category()
{
return category(ErrorCode{});
}
/**
* The error category which responsible for translating error codes to
* error messages.
*/
class error_category
{
public:
/**
* Returns the error category name.
*/
virtual std::string_view name() const noexcept = 0;
/**
* Return the error message for a given error code.
* For success codes, it is unspecified what value is returned.
* For convienience, you may return zpp::error::no_error for success.
* All other codes must return non empty string views.
*/
virtual std::string_view message(int code) const noexcept = 0;
/**
* Returns true if success code, else false.
*/
bool success(int code) const
{
return code == m_success_code;
}
protected:
/**
* Creates an error category whose success code is 'success_code'.
*/
constexpr error_category(int success_code) :
m_success_code(success_code)
{
}
/**
* Destroys the error category.
*/
~error_category() = default;
private:
/**
* The success code.
*/
int m_success_code{};
};
/**
* Creates an error category, whose name and success
* code are specified, as well as a message translation
* logic that returns the error message for every error code.
* Note: message translation must not throw.
*/
template <typename ErrorCode, typename Messages>
constexpr auto make_error_category(std::string_view name,
ErrorCode success_code,
Messages && messages)
{
// Create a category with the name and messages.
class category final : public error_category,
private std::remove_reference_t<Messages>
{
public:
constexpr category(std::string_view name,
ErrorCode success_code,
Messages && messages) :
error_category(
std::underlying_type_t<ErrorCode>(success_code)),
std::remove_reference_t<Messages>(
std::forward<Messages>(messages)),
m_name(name)
{
}
std::string_view name() const noexcept override
{
return m_name;
}
std::string_view message(int code) const noexcept override
{
return this->operator()(ErrorCode{code});
}
private:
std::string_view m_name;
} category(name, success_code, std::forward<Messages>(messages));
// Return the category.
return category;
}
/**
* Represents an error to be initialized from an error code
* enumeration.
* The error code enumeration must have 'int' as underlying type.
* Defining an error code enum and a category for it goes as follows.
* Example:
* ~~~
* namespace my_namespace
* {
* enum class my_error : int
* {
* success = 0,
* something_bad = 1,
* something_really_bad = 2,
* };
*
* inline const zpp::error_category & category(my_error)
* {
* constexpr static auto error_category =
* zpp::make_error_category("my_category", my_error::success,
* [](auto code) -> std::string_view {
* switch (code) {
* case my_error::success:
* return zpp::error::no_error;
* case my_code:something_bad:
* return "Something bad happened.";
* case my_error::something_really_bad:
* return "Something really bad happened.";
* default:
* return "Unknown error occurred.";
* }
* }
* );
* return error_category;
* }
* } // my_namespace
* ~~~
*/
class error
{
public:
/**
* Disables default construction.
*/
error() = delete;
/**
* Constructs an error from an error code enumeration, the
* category is looked by using argument dependent lookup on a
* function named 'category' that receives the error code
* enumeration value.
*/
template <typename ErrorCode>
error(ErrorCode error_code) :
m_category(std::addressof(
zpp::serializer::freestanding::category<ErrorCode>())),
m_code(std::underlying_type_t<ErrorCode>(error_code))
{
}
/**
* Constructs an error from an error code enumeration, the
* category is given explicitly in this overload.
*/
template <typename ErrorCode>
error(ErrorCode error_code, const error_category & category) :
m_category(std::addressof(category)),
m_code(std::underlying_type_t<ErrorCode>(error_code))
{
}
/**
* Returns the error category.
*/
const error_category & category() const
{
return *m_category;
}
/**
* Returns the error code.
*/
int code() const
{
return m_code;
}
/**
* Returns the error message. Calling this on
* a success error is implementation defined according
* to the error category.
*/
std::string_view message() const
{
return m_category->message(m_code);
}
/**
* Returns true if the error indicates success, else false.
*/
explicit operator bool() const
{
return m_category->success(m_code);
}
/**
* No error message value.
*/
static constexpr std::string_view no_error{};
private:
/**
* The error category.
*/
const error_category * m_category{};
/**
* The error code.
*/
int m_code{};
};
} // namespace freestanding
enum class error : int
{
success = 0,
out_of_range = 1,
variant_is_valueless = 2,
null_pointer_serialization = 3,
};
inline const freestanding::error_category & category(error)
{
constexpr static auto error_category =
freestanding::make_error_category(
"zpp::serializer",
error::success,
[](auto code) -> std::string_view {
switch (code) {
case error::success:
return freestanding::error::no_error;
case error::out_of_range:
return "[zpp::serializer] Out of range error";
case error::variant_is_valueless:
return "[zpp::serializer] Cannot serialize a "
"valueless variant.";
case error::null_pointer_serialization:
return "[zpp::serializer] Cannot serialize a null "
"pointer.";
default:
return "[zpp::serializer] Unknown error occurred.";
}
});
return error_category;
}
#endif // ZPP_SERIALIZER_FREESTANDING
namespace detail
{
/**
* Map any sequence of types to void.
*/
template <typename...>
using void_t = void;
/**
* Tests if all conditions are true, empty means true.
* Example:
* ~~~
* all_of<true, false, true>::value == false
* all_of<true, true>::value == true
* all_of<false, false>::value == false
* all_of<>::value == true
* ~~~
*/
template <bool... bConditions>
struct all_of : std::true_type
{
};
template <bool... bConditions>
struct all_of<false, bConditions...> : std::false_type
{
};
template <bool... bConditions>
struct all_of<true, bConditions...> : all_of<bConditions...>
{
};
template <>
struct all_of<true> : std::true_type
{
};
/**
* Remove const of container value_type
*/
template <typename Container, typename = void>
struct container_nonconst_value_type
{
using type = std::remove_const_t<typename Container::value_type>;
};
/**
* Same as above, except in case of std::map and std::unordered_map, and
* similar, we also need to remove the const of the key type.
*/
template <template <typename...> class Container,
typename KeyType,
typename MappedType,
typename... ExtraTypes>
struct container_nonconst_value_type<
Container<KeyType, MappedType, ExtraTypes...>,
void_t<
// Require existence of key_type.
typename Container<KeyType, MappedType, ExtraTypes...>::key_type,
// Require existence of mapped_type.
typename Container<KeyType, MappedType, ExtraTypes...>::
mapped_type,
// Require that the value type is a pair of const KeyType and
// MappedType.
std::enable_if_t<std::is_same<
std::pair<const KeyType, MappedType>,
typename Container<KeyType, MappedType, ExtraTypes...>::
value_type>::value>>>
{
using type = std::pair<KeyType, MappedType>;
};
/**
* Alias to the above.
*/
template <typename Container>
using container_nonconst_value_type_t =
typename container_nonconst_value_type<Container>::type;
/**
* The serializer exception template.
*/
template <typename Base, std::size_t Id>
class exception : public Base
{
public:
/**
* Use the constructors from the base class.
*/
using Base::Base;
};
/**
* A no operation, single byte has same representation in little/big
* endian.
*/
inline constexpr std::uint8_t swap_byte_order(std::uint8_t value) noexcept
{
return value;
}
/**
* Swaps the byte order of a given integer.
*/
inline constexpr std::uint16_t
swap_byte_order(std::uint16_t value) noexcept
{
return (std::uint16_t(swap_byte_order(std::uint8_t(value))) << 8) |
(swap_byte_order(std::uint8_t(value >> 8)));
}
/**
* Swaps the byte order of a given integer.
*/
inline constexpr std::uint32_t
swap_byte_order(std::uint32_t value) noexcept
{
return (std::uint32_t(swap_byte_order(std::uint16_t(value))) << 16) |
(swap_byte_order(std::uint16_t(value >> 16)));
}
/**
* Swaps the byte order of a given integer.
*/
inline constexpr std::uint64_t
swap_byte_order(std::uint64_t value) noexcept
{
return (std::uint64_t(swap_byte_order(std::uint32_t(value))) << 32) |
(swap_byte_order(std::uint32_t(value >> 32)));
}
/**
* Rotates the given number left by count bits.
*/
template <typename Integer>
constexpr auto rotate_left(Integer number, std::size_t count)
{
return (number << count) | (number >> ((sizeof(number) * 8) - count));
}
/**
* Checks if has 'data()' member function.
*/
template <typename Type, typename = void>
struct has_data_member_function : std::false_type
{
};
/**
* Checks if has 'data()' member function.
*/
template <typename Type>
struct has_data_member_function<
Type,
void_t<decltype(std::declval<Type &>().data())>> : std::true_type
{
};
} // namespace detail
/**
* @name Exceptions
* @{
*/
using out_of_range = detail::exception<std::out_of_range, 0>;
using undeclared_polymorphic_type_error =
detail::exception<std::runtime_error, 1>;
using attempt_to_serialize_null_pointer_error =
detail::exception<std::logic_error, 2>;
using polymorphic_type_mismatch_error =
detail::exception<std::runtime_error, 3>;
using attempt_to_serialize_valueless_variant =
detail::exception<std::runtime_error, 4>;
using variant_index_out_of_range = detail::exception<std::out_of_range, 5>;
/**
* @}
*/
/**
* If C++17 or greater, use shared mutex, else, use shared timed mutex.
*/
#ifndef ZPP_SERIALIZER_FREESTANDING
#if __cplusplus >= 201703L
/**
* The shared mutex type, defined to shared mutex when available.
*/
using shared_mutex = std::shared_mutex;
#else
/**
* The shared mutex type, defined to shared timed mutex when shared mutex
* is not available.
*/
using shared_mutex = std::shared_timed_mutex;
#endif
#endif
/**
* The base class for polymorphic serialization.
*/
class polymorphic
{
public:
/**
* Pure virtual destructor, in order to become abstract
* and make derived classes polymorphic.
*/
virtual ~polymorphic() = 0;
};
/**
* Default implementation for the destructor.
*/
inline polymorphic::~polymorphic() = default;
/**
* Allow serialization with saving (output) archives, of objects held by
* reference, that will be serialized as polymorphic, meaning, with leading
* polymorphic serialization id.
*/
template <typename Type>
class polymorphic_wrapper
{
public:
/**
* Constructs from the given object to be serialized as polymorphic.
*/
explicit polymorphic_wrapper(const Type & object) noexcept :
m_object(object)
{
static_assert(std::is_base_of<polymorphic, Type>::value,
"The given type is not derived from polymorphic");
}
/**
* Returns the object to be serialized as polymorphic.
*/
const Type & operator*() const noexcept
{
return m_object;
}
private:
/**
* The object to be serialized as polymorphic.
*/
const Type & m_object;
}; // polymorphic_wrapper
/**
* A facility to save object with leading polymorphic serialization id.
*/
template <typename Type>
auto as_polymorphic(const Type & object) noexcept
{
return polymorphic_wrapper<Type>(object);
}
/**
* The size type of the serializer.
* It is used to indicate the size for containers.
*/
using size_type = std::uint32_t;
/**
* The serialization id type,
*/
using id_type = std::uint64_t;
/**
* This class grants the serializer access to the serialized types.
*/
class access
{
public:
/**
* Allows placement construction of types.
*/
template <typename Item, typename... Arguments>
static auto
placement_new(void * pAddress, Arguments &&... arguments) noexcept(
noexcept(Item(std::forward<Arguments>(arguments)...)))
{
return ::new (pAddress)
Item(std::forward<Arguments>(arguments)...);
}
/**
* Allows dynamic construction of types.
* This overload is for non polymorphic serialization.
*/
template <typename Item,
typename... Arguments,
typename = std::enable_if_t<
!std::is_base_of<polymorphic, Item>::value>>
static auto make_unique(Arguments &&... arguments)
{
// Construct the requested type, using new since constructor might
// be private.
return std::unique_ptr<Item>(
new Item(std::forward<Arguments>(arguments)...));
}
/**
* Allows dynamic construction of types.
* This overload is for polymorphic serialization.
*/
template <typename Item,
typename... Arguments,
typename = std::enable_if_t<
std::is_base_of<polymorphic, Item>::value>,
typename = void>
static auto make_unique(Arguments &&... arguments)
{
// We create a deleter that will delete using the base class
// polymorphic which, as we declared, has a public virtual
// destructor.
struct deleter
{
void operator()(Item * item) noexcept
{
delete static_cast<polymorphic *>(item);
}
};
// Construct the requested type, using new since constructor might
// be private.
return std::unique_ptr<Item, deleter>(
new Item(std::forward<Arguments>(arguments)...));
}
/**
* Allows destruction of types.
*/
template <typename Item>
static void destruct(Item & item) noexcept
{
item.~Item();
}
}; // access
/**
* Enables serialization of arbitrary byte data.
* Use only with care.
*/
template <typename Item>
class bytes
{
public:
/**
* Constructs the bytes wrapper from pointer and count of items.
*/
bytes(Item * items, std::size_t count) : m_items(items), m_count(count)
{
}
/**
* Returns a pointer to the first item.
*/
Item * data() const noexcept
{
return m_items;
}
/**
* Returns the size in bytes of the bytes data.
*/
std::size_t size_in_bytes() const noexcept
{
return m_count * sizeof(Item);
}
/**
* Returns the count of items in the bytes wrapper.
*/
std::size_t count() const noexcept
{
return m_count;
}
private:
/**
* Pointer to the items.
*/
Item * m_items = nullptr;
/**
* The number of items.
*/
std::size_t m_count{};
};
/**
* Allows serialization as bytes data.
* Use only with care.
*/
template <typename Item>
bytes<Item> as_bytes(Item * item, std::size_t count)
{
static_assert(std::is_trivially_copyable<Item>::value,
"Must be trivially copyable");
return {item, count};
}
/**
* Allows serialization as bytes data.
* Use only with care.
*/
inline bytes<unsigned char> as_bytes(void * data, std::size_t size)
{
return {static_cast<unsigned char *>(data), size};
}
/**
* Allows serialization as bytes data.
*/
inline bytes<const unsigned char> as_bytes(const void * data,
std::size_t size)
{
return {static_cast<const unsigned char *>(data), size};
}
/**
* The serialization method type.
*/
template <typename Archive, typename = void>
struct serialization_method;
/**
* The serialization method type exporter, for loading (input) archives.
*/
template <typename Archive>
struct serialization_method<Archive, typename Archive::loading>
{
/**
* Disabled default constructor.
*/
serialization_method() = delete;
/**
* The exported type.
*/
using type = void (*)(Archive &, std::unique_ptr<polymorphic> &);
}; // serialization_method
/**
* The serialization method type exporter, for saving (output) archives.
*/
template <typename Archive>
struct serialization_method<Archive, typename Archive::saving>
{
/**
* Disabled default constructor.
*/
serialization_method() = delete;
/**
* The exported type.
*/
using type = void (*)(Archive &, const polymorphic &);
}; // serialization_method
/**
* The serialization method type.
*/
template <typename Archive>
using serialization_method_t =
typename serialization_method<Archive>::type;
/**
* Make a serialization method from type and a loading (input) archive.
*/
template <typename Archive,
typename Type,
typename...,
typename = typename Archive::loading>
serialization_method_t<Archive> make_serialization_method() noexcept
{
return [](Archive & archive, std::unique_ptr<polymorphic> & object) {
auto concrete_type = access::make_unique<Type>();
archive(*concrete_type);
object.reset(concrete_type.release());
};
}
/**
* Make a serialization method from type and a saving (output) archive.
*/
template <typename Archive,
typename Type,
typename...,
typename = typename Archive::saving,
typename = void>
serialization_method_t<Archive> make_serialization_method() noexcept
{
return [](Archive & archive, const polymorphic & object) {
archive(dynamic_cast<const Type &>(object));
};
}
/**
* This is the base archive of the serializer.
* It enables saving and loading items into/from the archive, via
* operator().
*/
template <typename ArchiveType>
class archive
{
public:
/**
* The derived archive type.
*/
using archive_type = ArchiveType;
/**
* Save/Load the given items into/from the archive.
*/
template <typename... Items>
auto operator()(Items &&... items)
{
// Disallow serialization of pointer types.
static_assert(
detail::all_of<!std::is_pointer<
std::remove_reference_t<Items>>::value...>::value,
"Serialization of pointer types is not allowed");
// Serialize the items.
return serialize_items(std::forward<Items>(items)...);
}
protected:
/**
* Constructs the archive.
*/
archive() = default;
/**
* Protected destructor to allow safe public inheritance.
*/
~archive() = default;
private:
/**
* Serialize the given items, one by one.
*/
template <typename Item, typename... Items>
auto serialize_items(Item && first, Items &&... items)
{
#ifndef ZPP_SERIALIZER_FREESTANDING