Feature #966
New function or explain: first and last for a vector?
Description
In CoCoA-5 we often first and last for making sub-lists.
This is tedious to translate into C++.
Make good C++ documentation, or write a trivial/inefficient function for handy-handling of short lists.
Related issues
History
#1 Updated by Anna Maria Bigatti over 7 years ago
- Related to Feature #357: Constructor for vectors? CoCoAVector added
#2 Updated by Anna Maria Bigatti over 7 years ago
- Assignee set to Anna Maria Bigatti
Equivalent to first,last
:
vector<RingElem>(x.begin(), x.end()-1)) vector<RingElem>(x.begin()+2, x.end()))
#3 Updated by John Abbott over 7 years ago
I am not yet convinced that first
and last
are good ideas for C++.
What exactly are the hoped-for semantics? Maybe last
can be implemented relatively efficiently, but I have doubts about first
.
I am concerned that they may make wasteful copies of the elements of the list/vector.
#4 Updated by Anna Maria Bigatti over 7 years ago
John Abbott wrote:
I am concerned that they may make wasteful copies of the elements of the list/vector.
Surely they do make wasteful copies. That's why I wrote "short lists" ;-)
Anyway, I'm adding some examples in ex-c++
.
#5 Updated by Anna Maria Bigatti over 5 years ago
- Category changed from New Function to Documentation
- Status changed from New to In Progress
- Target version changed from CoCoALib-1.0 to CoCoALib-0.99650 November 2019
- % Done changed from 0 to 20
#6 Updated by Anna Maria Bigatti over 5 years ago
- Subject changed from New function: first and last for a vector? to New function or explain: first and last for a vector?
#7 Updated by John Abbott over 4 years ago
- Target version changed from CoCoALib-0.99650 November 2019 to CoCoALib-0.99700
#8 Updated by Anna Maria Bigatti over 4 years ago
- Status changed from In Progress to Resolved
- % Done changed from 20 to 70
OK, I think we should not make a function in lib.
I added an example in ex-c++.C.
Now I realized that there is a ex-c++-vector.C
, so I think my original example should be split into the specific example files.
... not today.
In time for next release? not sure.
#9 Updated by John Abbott about 4 years ago
- Status changed from Resolved to Closed
- % Done changed from 70 to 100
- Estimated time changed from 3.00 h to 2.22 h
I have moved the example into a new file ex-c++-vector2.C
which illustrates how to "translate" the CoCoA-5 functions append
, first
and last
into C++.