libkazv
Loading...
Searching...
No Matches
std-optional.hpp
Go to the documentation of this file.
1/*
2 * This file is part of libkazv.
3 * SPDX-FileCopyrightText: 2021 Tusooa Zhu <tusooa@kazv.moe>
4 * SPDX-License-Identifier: AGPL-3.0-or-later
5 */
6
7
8#pragma once
9#include <libkazv-config.hpp>
10
11#include <boost/serialization/nvp.hpp>
12#include <boost/serialization/split_free.hpp>
13
14#include <optional>
15
17{
18 template<class Archive, class T>
19 void save(Archive &ar, const std::optional<T> &o, const unsigned int /* version */)
20 {
21 auto hasValue = o.has_value();
22 ar << BOOST_SERIALIZATION_NVP(hasValue);
23
24 if (hasValue) {
25 const auto &value = o.value();
26 ar << BOOST_SERIALIZATION_NVP(value);
27 }
28 }
29
30 template<class Archive, class T>
31 void load(Archive &ar, std::optional<T> &o, const unsigned int /* version */)
32 {
33 auto hasValue = bool{};
34 ar >> BOOST_SERIALIZATION_NVP(hasValue);
35
36 o.reset();
37
38 if (hasValue) {
39 T value;
40 ar >> BOOST_SERIALIZATION_NVP(value);
41 o = std::move(value);
42 }
43 }
44
45 template<class Archive,
46 class T>
47 inline void serialize(Archive &ar, std::optional<T> &o, const unsigned int version)
48 {
49 boost::serialization::split_free(ar, o, version);
50 }
51}
Definition immer-array.hpp:18
void load(Archive &ar, immer::array< T, MP > &v, const unsigned int)
Definition immer-array.hpp:35
void serialize(Archive &ar, immer::array< T, MP > &v, const unsigned int version)
Definition immer-array.hpp:58
void save(Archive &ar, const immer::array< T, MP > &v, const unsigned int)
Definition immer-array.hpp:22