lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 780cd0a 2/6: Remove a dependency that had bec


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 780cd0a 2/6: Remove a dependency that had become problematic
Date: Fri, 19 Mar 2021 17:54:42 -0400 (EDT)

branch: master
commit 780cd0a893c6ab07af3259afa29abf6d00f64607
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Remove a dependency that had become problematic
    
    After recent changes, the PETE makefile in this directory still built
    PETE correctly, but failed to build this unit test. The reason was that
    introducing lmi::ssize() required a modern C++ dialect, but the makefile
    invoked a compiler that defaulted to an old dialect.
    
    The simplest possible fix would be to add something like '-std=c++17'
    and just assume that the compiler is gcc; but that would vitiate commit
    a2528f32132ab9 of 20080907T1642Z ("Don't necessarily require g++").
    
    Instead, removed the local unit test's dependency on 'et_vector.hpp'
    (which includes 'ssize_lmi.hpp'), importing its crucial portions (cf.
    'tools/pete-2.1.1/html/tut-2.html') and modifying them to use
    std::vector.size() instead of lmi::ssize().
    
    This does not mean that 'et_vector.hpp' can be moved out of this
    subdirectory--as the next commit will explain.
---
 tools/pete-2.1.1/et_vector_test.cpp | 76 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 75 insertions(+), 1 deletion(-)

diff --git a/tools/pete-2.1.1/et_vector_test.cpp 
b/tools/pete-2.1.1/et_vector_test.cpp
index 42ef2ea..95e701d 100644
--- a/tools/pete-2.1.1/et_vector_test.cpp
+++ b/tools/pete-2.1.1/et_vector_test.cpp
@@ -19,12 +19,86 @@
 // email: <gchicares@sbcglobal.net>
 // snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
 
-#include "et_vector.hpp"
+#include "PETE/PETE.h"
 
 #include <algorithm>
 #include <functional>
 #include <iostream>
 #include <iterator>
+#include <vector>
+
+// Include "et_vector_operators.hpp" last because it's generated
+// automatically and doesn't include all the headers it needs.
+
+#include "et_vector_operators.hpp"
+
+/// Create vector-reference leaves.
+
+template<class T>
+struct CreateLeaf<std::vector<T>>
+{
+    typedef Reference<std::vector<T>> Leaf_t;
+    static Leaf_t make(std::vector<T> const& v) {return Leaf_t(v);}
+};
+
+/// Compare vector size with a stored value.
+
+class SizeLeaf
+{
+  public:
+    SizeLeaf(int s) : length_(s) {}
+    SizeLeaf(SizeLeaf const& model) : length_(model.length_) {}
+    bool operator()(int s) const {return length_ == s;}
+
+  private:
+    int length_;
+};
+
+template<class T>
+struct LeafFunctor<Scalar<T>, SizeLeaf>
+{
+    typedef bool Type_t;
+    static bool apply(Scalar<T> const&, SizeLeaf const&)
+    {
+        return true; // Scalars conform to any vector's length.
+    }
+};
+
+template<class T>
+struct LeafFunctor<std::vector<T>, SizeLeaf>
+{
+    typedef bool Type_t;
+    static bool apply(std::vector<T> const& v, SizeLeaf const& s)
+    {
+        return s(v.size());
+    }
+};
+
+template<class T>
+struct LeafFunctor<std::vector<T>, EvalLeaf1>
+{
+    typedef T Type_t;
+    static Type_t apply(std::vector<T> const& vec, EvalLeaf1 const& f)
+    {
+        return vec[f.val1()];
+    }
+};
+
+/// All PETE assignment operators call evaluate().
+
+template<class T, class Op, class U>
+inline void evaluate(std::vector<T>& t, Op const& op, Expression<U> const& u)
+{
+    if(!forEach(u, SizeLeaf(t.size()), AndCombine()))
+        {
+        throw std::runtime_error("Error: LHS and RHS don't conform.");
+        }
+
+    for(int i = 0; i < t.size(); ++i)
+        {
+        op(t[i], forEach(u, EvalLeaf1(i), OpCombine()));
+        }
+}
 
 template <typename T>
 void show_vector(std::vector<T> const& v)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]