Skip to content
Snippets Groups Projects
Commit dfad0b1b authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Rework vector<bool> conversion to string to satisfy libstdc++9

This is quite a stupid hack
parent fb973b01
No related branches found
No related tags found
1 merge request!144Add R^dxd and R^d expressions in pugs' language (with d=1,2 or 3)
...@@ -82,6 +82,15 @@ class AffectationExecutor final : public IAffectationExecutor ...@@ -82,6 +82,15 @@ class AffectationExecutor final : public IAffectationExecutor
return true; return true;
}()}; }()};
template <typename T>
std::string
_stringify(const T& value)
{
std::ostringstream os;
os << std::boolalpha << value;
return os.str();
}
public: public:
AffectationExecutor(ASTNode& node, ValueT& lhs) : m_lhs(lhs) AffectationExecutor(ASTNode& node, ValueT& lhs) : m_lhs(lhs)
{ {
...@@ -96,29 +105,19 @@ class AffectationExecutor final : public IAffectationExecutor ...@@ -96,29 +105,19 @@ class AffectationExecutor final : public IAffectationExecutor
affect(ExecutionPolicy&, DataVariant&& rhs) affect(ExecutionPolicy&, DataVariant&& rhs)
{ {
if constexpr (m_is_defined) { 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 (not std::is_same_v<DataT, ZeroType>) {
if constexpr (std::is_same_v<ValueT, std::string>) { 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<OperatorT, language::eq_op>) {
if constexpr (std::is_same_v<std::string, DataT>) { if constexpr (std::is_same_v<std::string, DataT>) {
m_lhs = std::get<DataT>(rhs); m_lhs = std::get<DataT>(rhs);
} else { } else {
m_lhs = std::move(stringify(std::get<DataT>(rhs))); m_lhs = std::move(_stringify(std::get<DataT>(rhs)));
} }
} else { } else {
if constexpr (std::is_same_v<std::string, DataT>) { if constexpr (std::is_same_v<std::string, DataT>) {
m_lhs += std::get<std::string>(rhs); m_lhs += std::get<std::string>(rhs);
} else { } else {
m_lhs += std::move(stringify(std::get<DataT>(rhs))); m_lhs += std::move(_stringify(std::get<DataT>(rhs)));
} }
} }
} else { } else {
...@@ -184,9 +183,16 @@ class AffectationExecutor final : public IAffectationExecutor ...@@ -184,9 +183,16 @@ class AffectationExecutor final : public IAffectationExecutor
std::visit( std::visit(
[&](auto&& v) { [&](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) { 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 { } else {
// LCOV_EXCL_START // LCOV_EXCL_START
...@@ -270,7 +276,7 @@ class AffectationExecutor final : public IAffectationExecutor ...@@ -270,7 +276,7 @@ class AffectationExecutor final : public IAffectationExecutor
std::is_convertible_v<T, ValueContentT>) { std::is_convertible_v<T, ValueContentT>) {
tuple_value[i] = static_cast<ValueContentT>(child_value); tuple_value[i] = static_cast<ValueContentT>(child_value);
} else if constexpr (std::is_same_v<std::string, ValueContentT>) { } 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>) { } else if constexpr (is_tiny_vector_v<ValueContentT>) {
if constexpr (std::is_arithmetic_v<T>) { if constexpr (std::is_arithmetic_v<T>) {
if constexpr (std::is_same_v<ValueContentT, TinyVector<1>>) { if constexpr (std::is_same_v<ValueContentT, TinyVector<1>>) {
...@@ -320,7 +326,7 @@ class AffectationExecutor final : public IAffectationExecutor ...@@ -320,7 +326,7 @@ class AffectationExecutor final : public IAffectationExecutor
std::is_convertible_v<T, ValueContentT>) { std::is_convertible_v<T, ValueContentT>) {
tuple_value[0] = static_cast<ValueContentT>(child_value); tuple_value[0] = static_cast<ValueContentT>(child_value);
} else if constexpr (std::is_same_v<std::string, ValueContentT>) { } 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>) { } else if constexpr (is_tiny_vector_v<ValueContentT>) {
if constexpr (std::is_arithmetic_v<T>) { if constexpr (std::is_arithmetic_v<T>) {
if constexpr (std::is_same_v<ValueContentT, TinyVector<1>>) { if constexpr (std::is_same_v<ValueContentT, TinyVector<1>>) {
...@@ -443,20 +449,19 @@ class AffectationToTupleProcessor final : public AffectationToDataVariantProcess ...@@ -443,20 +449,19 @@ class AffectationToTupleProcessor final : public AffectationToDataVariantProcess
private: private:
ASTNode& m_rhs_node; ASTNode& m_rhs_node;
public: template <typename T>
DataVariant std::string
execute(ExecutionPolicy& exec_policy) _stringify(const T& value)
{ {
auto stringify = [](auto&& value) {
std::ostringstream os; std::ostringstream os;
if constexpr (std::is_same_v<std::decay_t<decltype(value)>, bool>) {
os << std::boolalpha << value; os << std::boolalpha << value;
} else {
os << value;
}
return os.str(); return os.str();
}; }
public:
DataVariant
execute(ExecutionPolicy& exec_policy)
{
DataVariant value = m_rhs_node.execute(exec_policy); DataVariant value = m_rhs_node.execute(exec_policy);
std::visit( std::visit(
...@@ -467,7 +472,7 @@ class AffectationToTupleProcessor final : public AffectationToDataVariantProcess ...@@ -467,7 +472,7 @@ class AffectationToTupleProcessor final : public AffectationToDataVariantProcess
} else if constexpr (std::is_arithmetic_v<ValueT> and std::is_convertible_v<T, ValueT>) { } 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))}; *m_lhs = std::vector{std::move(static_cast<ValueT>(v))};
} else if constexpr (std::is_same_v<std::string, ValueT>) { } 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>) { } 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>) { 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)}}; *m_lhs = std::vector<TinyVector<1>>{TinyVector<1>{static_cast<double>(v)}};
...@@ -503,19 +508,18 @@ class AffectationToTupleFromListProcessor final : public AffectationToDataVarian ...@@ -503,19 +508,18 @@ class AffectationToTupleFromListProcessor final : public AffectationToDataVarian
private: private:
ASTNode& m_rhs_node; ASTNode& m_rhs_node;
void template <typename T>
_copyAggregateDataVariant(const AggregateDataVariant& children_values) std::string
_stringify(const T& value)
{ {
auto stringify = [](auto&& value) {
std::ostringstream os; std::ostringstream os;
if constexpr (std::is_same_v<std::decay_t<decltype(value)>, bool>) {
os << std::boolalpha << value; os << std::boolalpha << value;
} else {
os << value;
}
return os.str(); return os.str();
}; }
void
_copyAggregateDataVariant(const AggregateDataVariant& children_values)
{
std::vector<ValueT> tuple_value(children_values.size()); std::vector<ValueT> tuple_value(children_values.size());
for (size_t i = 0; i < children_values.size(); ++i) { for (size_t i = 0; i < children_values.size(); ++i) {
std::visit( std::visit(
...@@ -526,7 +530,7 @@ class AffectationToTupleFromListProcessor final : public AffectationToDataVarian ...@@ -526,7 +530,7 @@ class AffectationToTupleFromListProcessor final : public AffectationToDataVarian
} else if constexpr (std::is_arithmetic_v<ValueT> and std::is_convertible_v<T, ValueT>) { } else if constexpr (std::is_arithmetic_v<ValueT> and std::is_convertible_v<T, ValueT>) {
tuple_value[i] = static_cast<ValueT>(child_value); tuple_value[i] = static_cast<ValueT>(child_value);
} else if constexpr (std::is_same_v<std::string, ValueT>) { } 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>) { } else if constexpr (is_tiny_vector_v<ValueT>) {
if constexpr (std::is_arithmetic_v<T>) { if constexpr (std::is_arithmetic_v<T>) {
if constexpr (std::is_same_v<ValueT, TinyVector<1>>) { if constexpr (std::is_same_v<ValueT, TinyVector<1>>) {
...@@ -573,16 +577,6 @@ class AffectationToTupleFromListProcessor final : public AffectationToDataVarian ...@@ -573,16 +577,6 @@ class AffectationToTupleFromListProcessor final : public AffectationToDataVarian
void void
_copyVector(const std::vector<DataType>& values) _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()); std::vector<ValueT> v(values.size());
if constexpr (std::is_same_v<ValueT, DataType>) { if constexpr (std::is_same_v<ValueT, DataType>) {
for (size_t i = 0; i < values.size(); ++i) { for (size_t i = 0; i < values.size(); ++i) {
...@@ -594,7 +588,7 @@ class AffectationToTupleFromListProcessor final : public AffectationToDataVarian ...@@ -594,7 +588,7 @@ class AffectationToTupleFromListProcessor final : public AffectationToDataVarian
} }
} else if constexpr (std::is_same_v<ValueT, std::string>) { } else if constexpr (std::is_same_v<ValueT, std::string>) {
for (size_t i = 0; i < values.size(); ++i) { for (size_t i = 0; i < values.size(); ++i) {
v[i] = std::move(stringify(values[i])); v[i] = std::move(_stringify(values[i]));
} }
} else { } else {
// LCOV_EXCL_START // LCOV_EXCL_START
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment