From 754f74df01c9d5fd21714571dc040e65bf82fbc6 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Thu, 11 Jun 2020 09:35:32 +0200 Subject: [PATCH] Adapt variant serialization to four types --- ebos/eclmpiserializer.hh | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/ebos/eclmpiserializer.hh b/ebos/eclmpiserializer.hh index 427a06c3b..0f268a8c0 100644 --- a/ebos/eclmpiserializer.hh +++ b/ebos/eclmpiserializer.hh @@ -103,22 +103,22 @@ public: The std::variant<> serialization is a first attempt and *not* particularly general. In particular that implies: - 1. It is hardcoded to hold exactly three alternative types T1, T2 and + 1. It is hardcoded to hold exactly four alternative types T0, T1, T2 and T3. - 2. All the three types T1, T2 and T3 must implement the ::serializeOp( ) + 2. All the four types T0, T1, T2 and T3 must implement the ::serializeOp( ) method. This implies that a variant with a fundamental type like e.g. - std::variant will *not* work in the + std::variant will *not* work in the current implementation. */ - template - void variant(const std::variant& _data) + template + void variant(const std::variant& _data) { auto handle = [&](auto& d) { d.serializeOp(*this); }; - std::variant& data = const_cast&>(_data); + std::variant& data = const_cast&>(_data); if (m_op == Operation::PACKSIZE) { m_packSize += Mpi::packSize(data.index(), m_comm); std::visit( [&] (auto& arg) { handle(arg); }, data); @@ -130,16 +130,19 @@ public: Mpi::unpack(index, m_buffer, m_position, m_comm); if (index == 0) { - data = T1(); + data = T0(); handle(std::get<0>(data)); } else if (index == 1) { - data = T2(); + data = T1(); handle(std::get<1>(data)); } else if (index == 2) { - data = T3(); + data = T2(); handle(std::get<2>(data)); + } else if (index == 3) { + data = T3(); + handle(std::get<3>(data)); } else - std::logic_error("Internal meltdown in std::variant unpack"); + std::logic_error("Internal meltdown in std::variant unpack"); } }