Hi, sometimes GiNaCs templates are a mystery to me. In container.h there is the code template<template<classT, class= std::allocator<T>> classC> container<C> & container<C>::prepend(constex & b) { ensure_if_modifiable(); this->seq.push_front(b); return*this; } but AFAIK the STL does not have any push_front() method. And GiNaC does not seem to define it either. How can this work? Same applies for pop_front() and sort() voidsort_(std::input_iterator_tag) { this->seq.sort(ex_is_less()); } Jan Rheinländer
Hi Jan, On 02.03.22 18:55, Jan Rheinländer wrote:
sometimes GiNaCs templates are a mystery to me. In container.h there is the code
template<template<classT, class= std::allocator<T>> classC> container<C> & container<C>::prepend(constex & b) { ensure_if_modifiable(); this->seq.push_front(b); return*this; }
but AFAIK the STL does not have any push_front() method. And GiNaC does not seem to define it either. How can this work?
Same applies for pop_front() and sort()
voidsort_(std::input_iterator_tag) { this->seq.sort(ex_is_less()); }
Well, not every STL container provides every possible method. But the standard does require the ones you mention for the instantiated template classes. Check again! -richy. -- Richard B. Kreckel <https://in.terlu.de/~kreckel/>
Hi Richard, but when I try to compile this program #include <ginac/ginac.h> using namespace GiNaC; int main(int argc, char** argv) { exprseq seq{1,2,3}; seq.prepend(0); return 0; } I get error: In file included from /usr/include/ginac/lst.h:26, from /usr/include/ginac/normal.h:29, from /usr/include/ginac/ginac.h:31, from test.cpp:24: /usr/include/ginac/container.h: In instantiation of ‘GiNaC::container<C>& GiNaC::container< <template-parameter-1-1>
::prepend(const GiNaC::ex&) [with C = std::vector]’: test.cpp:30:15: required from here /usr/include/ginac/container.h:551:12: error: ‘GiNaC::container_storage<std::vector>::STLT’ {aka ‘class std::vector<GiNaC::ex>’} has no member named ‘push_front’ 551 | this->seq.push_front(b); | ~~~~~~~~~~^~~~~~~~~~
Why not change the code of prepend() in container.h to use insert() instead of push_front()? Then I think it will work for all STL containers. Jan Am 02.03.22 um 23:44 schrieb Richard B. Kreckel:
Hi Jan,
On 02.03.22 18:55, Jan Rheinländer wrote:
sometimes GiNaCs templates are a mystery to me. In container.h there is the code
template<template<classT, class= std::allocator<T>> classC> container<C> & container<C>::prepend(constex & b) { ensure_if_modifiable(); this->seq.push_front(b); return*this; }
but AFAIK the STL does not have any push_front() method. And GiNaC does not seem to define it either. How can this work?
Same applies for pop_front() and sort()
voidsort_(std::input_iterator_tag) { this->seq.sort(ex_is_less()); } Well, not every STL container provides every possible method. But the standard does require the ones you mention for the instantiated template classes. Check again!
-richy.
Hi Jan, On 04.03.22 17:54, Jan Rheinländer wrote:
Why not change the code of prepend() in container.h to use insert() instead of push_front()? Then I think it will work for all STL containers.
We always welcome suggestions and we welcome patches which have been tried out successfully even more! -richy.
Hi Richard, here are two patches: One for push_front() / pop_front(), the other for sort(). Jan Am 05.03.22 um 12:49 schrieb Richard B. Kreckel:
Hi Jan,
Why not change the code of prepend() in container.h to use insert() instead of push_front()? Then I think it will work for all STL containers. We always welcome suggestions and we welcome patches which have been
On 04.03.22 17:54, Jan Rheinländer wrote: tried out successfully even more!
-richy. _______________________________________________ GiNaC-devel mailing list GiNaC-devel@ginac.de https://www.ginac.de/mailman/listinfo/ginac-devel
Hi Jan, On 05.03.22 15:18, Jan Rheinländer wrote:
here are two patches: One for push_front() / pop_front(), the other for sort().
Are you sure you want to container<std::vector>::prepend()? It's very slow. For std::list and std::deque, .push_front() and .insert(.begin) seem to be equally fast. So, your first patch techniqually at least not a regression. Your second patch makes container::sort_(std::input_iterator_tag) use std::sort. That seems wrong to me because std::sort requires a random access iterator. And std::list iterators are only bidirectional, not random access. (Note that random_access_iterator_tag is derived from input_iterator_tag.) Could you explain why you needed this second patch? -richy.
Hi Richard, I don't really "need" any of these patches. Just that it seems wrong to me that a program using exprseq::prepend() does not compile. But maybe that is intended because it is really inefficient? Am 05.03.22 um 20:24 schrieb Richard B. Kreckel:
Hi Jan,
On 05.03.22 15:18, Jan Rheinländer wrote:
here are two patches: One for push_front() / pop_front(), the other for sort(). Are you sure you want to container<std::vector>::prepend()? It's very slow. For std::list and std::deque, .push_front() and .insert(.begin) seem to be equally fast. So, your first patch techniqually at least not a regression.
Your second patch makes container::sort_(std::input_iterator_tag) use std::sort. That seems wrong to me because std::sort requires a random access iterator. And std::list iterators are only bidirectional, not random access. (Note that random_access_iterator_tag is derived from input_iterator_tag.) Could you explain why you needed this second patch?
-richy. _______________________________________________ GiNaC-devel mailing list GiNaC-devel@ginac.de https://www.ginac.de/mailman/listinfo/ginac-devel
Hi Jan, On 05.03.22 21:36, Jan Rheinländer wrote:
I don't really "need" any of these patches. Just that it seems wrong to me that a program using exprseq::prepend() does not compile. But maybe that is intended because it is really inefficient?
Understood. And what about the sort patch? What exactly does not compile? -richy.
Hi Richard, sorry, I think I was too quick with the sort() patch. I can't reproduce the problem any more. So forget about it. Jan Am 05.03.22 um 23:41 schrieb Richard B. Kreckel:
Hi Jan,
On 05.03.22 21:36, Jan Rheinländer wrote:
I don't really "need" any of these patches. Just that it seems wrong to me that a program using exprseq::prepend() does not compile. But maybe that is intended because it is really inefficient? Understood. And what about the sort patch? What exactly does not compile?
-richy. _______________________________________________ GiNaC-devel mailing list GiNaC-devel@ginac.de https://www.ginac.de/mailman/listinfo/ginac-devel
participants (2)
-
Jan Rheinländer
-
Richard B. Kreckel