From ce9a9baeffcdc1c2110712b36da8f559691f3ef5 Mon Sep 17 00:00:00 2001
From: Ben Cumming <bcumming@cscs.ch>
Date: Tue, 8 Sep 2020 08:16:25 +0200
Subject: [PATCH] remove arb::util::either from Python interface (#1138)

Switch `arb::util::either` to `arb::util::variant` in the Python wrapper.

Fixes #1133
---
 python/s_expr.cpp    |  6 ++----
 python/s_expr.hpp    | 10 +++++-----
 python/strprintf.hpp |  2 --
 3 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/python/s_expr.cpp b/python/s_expr.cpp
index 129d1080..6360713c 100644
--- a/python/s_expr.cpp
+++ b/python/s_expr.cpp
@@ -1,5 +1,3 @@
-#include <iostream>
-
 #include <cctype>
 #include <cstring>
 #include <string>
@@ -7,8 +5,8 @@
 #include <ostream>
 #include <vector>
 
-#include <arbor/util/either.hpp>
 #include <arbor/arbexcept.hpp>
+#include <arbor/util/variant.hpp>
 
 #include "s_expr.hpp"
 #include "strprintf.hpp"
@@ -298,7 +296,7 @@ bool test_identifier(const char* in) {
 //
 
 bool s_expr::is_atom() const {
-    return (bool)state;
+    return state.index()==0;
 }
 
 const token& s_expr::atom() const {
diff --git a/python/s_expr.hpp b/python/s_expr.hpp
index 37975ee7..8c4dd433 100644
--- a/python/s_expr.hpp
+++ b/python/s_expr.hpp
@@ -5,7 +5,7 @@
 #include <vector>
 
 #include <arbor/util/either.hpp>
-#include <arbor/util/optional.hpp>
+#include <arbor/util/variant.hpp>
 
 namespace pyarb {
 
@@ -85,12 +85,12 @@ struct s_expr {
     // An s_expr can be one of
     //      1. an atom
     //      2. a pair of s_expr (head and tail)
-    // The s_expr uses a util::either to represent these two possible states,
-    // which requires using an incomplete definition of s_expr, requiring
-    // with a std::shared_ptr.
+    // The s_expr uses a util::variant to represent these two possible states,
+    // which requires using an incomplete definition of s_expr, which is stored
+    // using a std::unique_ptr.
 
     using pair_type = s_pair<value_wrapper<s_expr>>;
-    arb::util::either<token, pair_type> state = token{-1, tok::nil, "nil"};
+    arb::util::variant<token, pair_type> state = token{-1, tok::nil, "nil"};
 
     s_expr(const s_expr& s): state(s.state) {}
     s_expr() = default;
diff --git a/python/strprintf.hpp b/python/strprintf.hpp
index 9e468712..5e2699bd 100644
--- a/python/strprintf.hpp
+++ b/python/strprintf.hpp
@@ -13,8 +13,6 @@
 
 #include <arbor/util/optional.hpp>
 
-#include "s_expr.hpp"
-
 namespace pyarb {
 namespace util {
 
-- 
GitLab