[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 4c4a0e4 4/8: Add a PETE length-of function
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 4c4a0e4 4/8: Add a PETE length-of function |
Date: |
Sat, 20 Mar 2021 09:55:30 -0400 (EDT) |
branch: master
commit 4c4a0e44470f0ef393308313208dc353e5e73e66
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Add a PETE length-of function
Alternatively, lmi::ssize() could be specialized for this, but that
would be freakish.
---
et_vector_test.cpp | 4 ++++
tools/pete-2.1.1/et_vector.hpp | 8 ++++++++
2 files changed, 12 insertions(+)
diff --git a/et_vector_test.cpp b/et_vector_test.cpp
index 57bfd18..4e67020 100644
--- a/et_vector_test.cpp
+++ b/et_vector_test.cpp
@@ -40,6 +40,10 @@ int test_main(int, char*[])
std::vector<double> v1 = {2.0, 3.0, 4.0};
LMI_TEST_EQUAL(3, forEach(v0, LengthLeaf(), MaxCombine()));
LMI_TEST_EQUAL(3, forEach(v0 / v1 + v0 * v1, LengthLeaf(), MaxCombine()));
+ // Rho(std::vector<T> const&) could be supported, of course, but
+ // it seems better to restrict Rho() to 'Expression' instances.
+// LMI_TEST_EQUAL(3, Rho(v0));
+ LMI_TEST_EQUAL(3, Rho(v0 / v1 + v0 * v1));
}
// Test non-conformable assignment.
diff --git a/tools/pete-2.1.1/et_vector.hpp b/tools/pete-2.1.1/et_vector.hpp
index 75123c5..3bb6f05 100644
--- a/tools/pete-2.1.1/et_vector.hpp
+++ b/tools/pete-2.1.1/et_vector.hpp
@@ -167,6 +167,14 @@ struct Combine2<int, int, Op, MaxCombine>
}
};
+/// Like APL's monadic 'rho': return argument's length.
+
+template<typename T>
+inline int Rho(Expression<T> const& t)
+{
+ return forEach(t, LengthLeaf(), MaxCombine());
+}
+
/// All PETE assignment operators call evaluate().
template<typename T, typename Op, typename U>
- [lmi-commits] [lmi] master updated (1be41b7 -> 1d15a4a), Greg Chicares, 2021/03/20
- [lmi-commits] [lmi] master d5f870a 1/8: Improve documentation, Greg Chicares, 2021/03/20
- [lmi-commits] [lmi] master 4220f5e 2/8: Assume default allocator always, Greg Chicares, 2021/03/20
- [lmi-commits] [lmi] master 44b780e 7/8: Deduce Eval()'s return type, Greg Chicares, 2021/03/20
- [lmi-commits] [lmi] master de67a28 5/8: Improve an error message, Greg Chicares, 2021/03/20
- [lmi-commits] [lmi] master cd6c9ea 3/8: Favor the One True type-parameter-key, Greg Chicares, 2021/03/20
- [lmi-commits] [lmi] master 4c4a0e4 4/8: Add a PETE length-of function,
Greg Chicares <=
- [lmi-commits] [lmi] master 1d15a4a 8/8: Isolate PETE directory weirdness to a redirection header, Greg Chicares, 2021/03/20
- [lmi-commits] [lmi] master 334ac64 6/8: Add a function template to transform a PETE expression to a std::vector, Greg Chicares, 2021/03/20