From dfad0b1bef112e4c896bf2dbc2d46275aec2a587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com> Date: Thu, 30 Jun 2022 11:33:38 +0200 Subject: [PATCH] Rework vector<bool> conversion to string to satisfy libstdc++9 This is quite a stupid hack --- .../node_processor/AffectationProcessor.hpp | 92 +++++++++---------- 1 file changed, 43 insertions(+), 49 deletions(-) diff --git a/src/language/node_processor/AffectationProcessor.hpp b/src/language/node_processor/AffectationProcessor.hpp index 3a354f2a4..bb9b7f036 100644 --- a/src/language/node_processor/AffectationProcessor.hpp +++ b/src/language/node_processor/AffectationProcessor.hpp @@ -82,6 +82,15 @@ class AffectationExecutor final : public IAffectationExecutor return true; }()}; + template <typename T> + std::string + _stringify(const T& value) + { + std::ostringstream os; + os << std::boolalpha << value; + return os.str(); + } + public: AffectationExecutor(ASTNode& node, ValueT& lhs) : m_lhs(lhs) { @@ -96,29 +105,19 @@ class AffectationExecutor final : public IAffectationExecutor affect(ExecutionPolicy&, DataVariant&& rhs) { if constexpr (m_is_defined) { - auto stringify = [](auto&& value) { - std::ostringstream os; - if constexpr (std::is_same_v<std::decay_t<decltype(value)>, bool>) { - os << std::boolalpha << value; - } else { - os << value; - } - return os.str(); - }; - if constexpr (not std::is_same_v<DataT, ZeroType>) { if constexpr (std::is_same_v<ValueT, std::string>) { if constexpr (std::is_same_v<OperatorT, language::eq_op>) { if constexpr (std::is_same_v<std::string, DataT>) { m_lhs = std::get<DataT>(rhs); } else { - m_lhs = std::move(stringify(std::get<DataT>(rhs))); + m_lhs = std::move(_stringify(std::get<DataT>(rhs))); } } else { if constexpr (std::is_same_v<std::string, DataT>) { m_lhs += std::get<std::string>(rhs); } else { - m_lhs += std::move(stringify(std::get<DataT>(rhs))); + m_lhs += std::move(_stringify(std::get<DataT>(rhs))); } } } else { @@ -184,9 +183,16 @@ class AffectationExecutor final : public IAffectationExecutor std::visit( [&](auto&& v) { - if constexpr (is_std_vector_v<std::decay_t<decltype(v)>>) { + using V_T = std::decay_t<decltype(v)>; + if constexpr (is_std_vector_v<V_T>) { for (size_t i = 0; i < v.size(); ++i) { - m_lhs[i] = std::move(stringify(v[i])); + if constexpr (std::is_same_v<typename V_T::value_type, bool>) { + // Ugly workaround to allow compilation with libstdc++-9 + bool v_i = v[i]; + m_lhs[i] = std::move(_stringify(v_i)); + } else { + m_lhs[i] = std::move(_stringify(v[i])); + } } } else { // LCOV_EXCL_START @@ -270,7 +276,7 @@ class AffectationExecutor final : public IAffectationExecutor std::is_convertible_v<T, ValueContentT>) { tuple_value[i] = static_cast<ValueContentT>(child_value); } else if constexpr (std::is_same_v<std::string, ValueContentT>) { - tuple_value[i] = std::move(stringify(child_value)); + tuple_value[i] = std::move(_stringify(child_value)); } else if constexpr (is_tiny_vector_v<ValueContentT>) { if constexpr (std::is_arithmetic_v<T>) { if constexpr (std::is_same_v<ValueContentT, TinyVector<1>>) { @@ -320,7 +326,7 @@ class AffectationExecutor final : public IAffectationExecutor std::is_convertible_v<T, ValueContentT>) { tuple_value[0] = static_cast<ValueContentT>(child_value); } else if constexpr (std::is_same_v<std::string, ValueContentT>) { - tuple_value[0] = std::move(stringify(child_value)); + tuple_value[0] = std::move(_stringify(child_value)); } else if constexpr (is_tiny_vector_v<ValueContentT>) { if constexpr (std::is_arithmetic_v<T>) { if constexpr (std::is_same_v<ValueContentT, TinyVector<1>>) { @@ -443,20 +449,19 @@ class AffectationToTupleProcessor final : public AffectationToDataVariantProcess private: ASTNode& m_rhs_node; + template <typename T> + std::string + _stringify(const T& value) + { + std::ostringstream os; + os << std::boolalpha << value; + return os.str(); + } + public: DataVariant execute(ExecutionPolicy& exec_policy) { - auto stringify = [](auto&& value) { - std::ostringstream os; - if constexpr (std::is_same_v<std::decay_t<decltype(value)>, bool>) { - os << std::boolalpha << value; - } else { - os << value; - } - return os.str(); - }; - DataVariant value = m_rhs_node.execute(exec_policy); std::visit( @@ -467,7 +472,7 @@ class AffectationToTupleProcessor final : public AffectationToDataVariantProcess } else if constexpr (std::is_arithmetic_v<ValueT> and std::is_convertible_v<T, ValueT>) { *m_lhs = std::vector{std::move(static_cast<ValueT>(v))}; } else if constexpr (std::is_same_v<std::string, ValueT>) { - *m_lhs = std::vector{std::move(stringify(v))}; + *m_lhs = std::vector{std::move(_stringify(v))}; } else if constexpr (is_tiny_vector_v<ValueT> or is_tiny_matrix_v<ValueT>) { if constexpr (std::is_same_v<ValueT, TinyVector<1>> and std::is_arithmetic_v<T>) { *m_lhs = std::vector<TinyVector<1>>{TinyVector<1>{static_cast<double>(v)}}; @@ -503,19 +508,18 @@ class AffectationToTupleFromListProcessor final : public AffectationToDataVarian private: ASTNode& m_rhs_node; + template <typename T> + std::string + _stringify(const T& value) + { + std::ostringstream os; + os << std::boolalpha << value; + return os.str(); + } + void _copyAggregateDataVariant(const AggregateDataVariant& children_values) { - auto stringify = [](auto&& value) { - std::ostringstream os; - if constexpr (std::is_same_v<std::decay_t<decltype(value)>, bool>) { - os << std::boolalpha << value; - } else { - os << value; - } - return os.str(); - }; - std::vector<ValueT> tuple_value(children_values.size()); for (size_t i = 0; i < children_values.size(); ++i) { std::visit( @@ -526,7 +530,7 @@ class AffectationToTupleFromListProcessor final : public AffectationToDataVarian } else if constexpr (std::is_arithmetic_v<ValueT> and std::is_convertible_v<T, ValueT>) { tuple_value[i] = static_cast<ValueT>(child_value); } else if constexpr (std::is_same_v<std::string, ValueT>) { - tuple_value[i] = std::move(stringify(child_value)); + tuple_value[i] = std::move(_stringify(child_value)); } else if constexpr (is_tiny_vector_v<ValueT>) { if constexpr (std::is_arithmetic_v<T>) { if constexpr (std::is_same_v<ValueT, TinyVector<1>>) { @@ -573,16 +577,6 @@ class AffectationToTupleFromListProcessor final : public AffectationToDataVarian void _copyVector(const std::vector<DataType>& values) { - auto stringify = [](auto&& value) { - std::ostringstream os; - if constexpr (std::is_same_v<std::decay_t<decltype(value)>, bool>) { - os << std::boolalpha << value; - } else { - os << value; - } - return os.str(); - }; - std::vector<ValueT> v(values.size()); if constexpr (std::is_same_v<ValueT, DataType>) { for (size_t i = 0; i < values.size(); ++i) { @@ -594,7 +588,7 @@ class AffectationToTupleFromListProcessor final : public AffectationToDataVarian } } else if constexpr (std::is_same_v<ValueT, std::string>) { for (size_t i = 0; i < values.size(); ++i) { - v[i] = std::move(stringify(values[i])); + v[i] = std::move(_stringify(values[i])); } } else { // LCOV_EXCL_START -- GitLab