From e9bd666f2ed86fd02b5f0c59538327d1d00db3ec Mon Sep 17 00:00:00 2001 From: Richard Kreckel Date: Mon, 5 Aug 2002 22:03:01 +0000 Subject: [PATCH] * Add virtual method remove_all() to the containers (by Roberto Bagnara). --- doc/tutorial/ginac.texi | 11 ++++++++++- ginac/container.pl | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/tutorial/ginac.texi b/doc/tutorial/ginac.texi index 3c88ec30..2e06d46b 100644 --- a/doc/tutorial/ginac.texi +++ b/doc/tutorial/ginac.texi @@ -1214,6 +1214,7 @@ canonical form. @cindex @code{prepend()} @cindex @code{remove_first()} @cindex @code{remove_last()} +@cindex @code{remove_all()} The GiNaC class @code{lst} serves for holding a @dfn{list} of arbitrary expressions. These are sometimes used to supply a variable number of @@ -1251,13 +1252,21 @@ and @code{prepend()} methods: // ... @end example -Finally you can remove the first or last element of a list with +You can remove the first or last element of a list with @code{remove_first()} and @code{remove_last()}: @example // ... l.remove_first(); // l is now @{x, 2, y, x+y, 4*x@} l.remove_last(); // l is now @{x, 2, y, x+y@} +@end example + +Finally, you can remove all the elements of a list with +@code{remove_all()}: + +@example + // ... + l.remove_all(); // l is now empty @} @end example diff --git a/ginac/container.pl b/ginac/container.pl index d187d065..2860ccf1 100755 --- a/ginac/container.pl +++ b/ginac/container.pl @@ -250,6 +250,7 @@ protected: public: virtual ${CONTAINER} & append(const ex & b); virtual ${CONTAINER} & remove_last(void); + virtual ${CONTAINER} & remove_all(void); ${PREPEND_INTERFACE} ${SORT_INTERFACE} protected: @@ -547,6 +548,13 @@ ${CONTAINER} & ${CONTAINER}::remove_last(void) return *this; } +${CONTAINER} & ${CONTAINER}::remove_all(void) +{ + ensure_if_modifiable(); + seq.clear(); + return *this; +} + ${PREPEND_IMPLEMENTATION} ${SORT_IMPLEMENTATION} -- 2.49.0