ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
variant.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <boost/serialization/split_free.hpp>
23
24#include <cstddef>
25#include <stdexcept>
26#include <utility>
27#include <variant>
28
29namespace boost::serialization {
30
31namespace detail {
32template <std::size_t I, class Archive, class Variant>
33void load_impl(Archive &ar, std::size_t index, Variant &obj) {
34 if (index == I) {
35 std::variant_alternative_t<I, Variant> opt{};
36 ar >> opt;
37 obj.template emplace<I>(std::move(opt));
38 } else if constexpr (I + 1 < std::variant_size_v<Variant>) {
39 load_impl<I + 1>(ar, index, obj);
40 }
41}
42} // namespace detail
43
44template <class Archive, class... Ts>
45void save(Archive &ar, std::variant<Ts...> const &obj, unsigned const) {
46 ar << obj.index();
47 std::visit([&](const auto &value) { ar << value; }, obj);
48}
49
50template <class Archive, class... Ts>
51void load(Archive &ar, std::variant<Ts...> &obj, unsigned const) {
52 std::size_t index = 0;
53 ar >> index;
54 if (index >= std::variant_size_v<std::variant<Ts...>>) {
55 throw std::domain_error("std::variant cannot be reloaded (type mismatch)");
56 }
57 detail::load_impl<0>(ar, index, obj);
58}
59
60template <class Archive, class... Ts>
61void serialize(Archive &ar, std::variant<Ts...> &obj, unsigned const version) {
63}
64
65} // namespace boost::serialization
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
void serialize(Archive &ar, std::tuple< T... > &pack, unsigned int const)
Serialize std::tuple.
void load(Archive &ar, GpuParticleData::GpuParticle &p, unsigned const)
void save(Archive &ar, GpuParticleData::GpuParticle const &p, unsigned const)