Project

General

Profile

Design #1346

C++14: use the new for loop syntax where appropriate (like cocoa's foreach)

Added by John Abbott over 4 years ago. Updated 5 days ago.

Status:
In Progress
Priority:
Normal
Assignee:
-
Category:
Improving
Target version:
Start date:
21 Oct 2019
Due date:
% Done:

80%

Estimated time:
Spent time:

Description

Since C++11 there is a new "range-based" for loop.

Employ it where appropriate in CoCoALib.


Related issues

Related to CoCoALib - Design #1225: Move to C++14 (skipping C++11)In Progress2018-09-06

Related to CoCoALib - Design #1242: C++14: Use type auto where appropriateIn Progress2019-02-08

Related to CoCoALib - Feature #1472: Idea for for loopsIn Progress2020-07-23

Related to CoCoA-5 - Design #1520: Replace BOOST_FOREACH by new C++14 range for syntaxClosed2020-10-26

History

#1 Updated by John Abbott over 4 years ago

  • Related to Design #1225: Move to C++14 (skipping C++11) added

#2 Updated by John Abbott over 4 years ago

We should maintain a list of files to change and/or a list of files already changed.
  • SparsePolyOps-ideal-monomial.C
  • TmpPPVector.C

#3 Updated by John Abbott over 4 years ago

  • Related to Design #1242: C++14: Use type auto where appropriate added

#4 Updated by Anna Maria Bigatti over 4 years ago

used massively for monomial ideals.
Tested.
cvs-ed.

#5 Updated by Anna Maria Bigatti over 4 years ago

  • Status changed from New to In Progress
  • % Done changed from 0 to 10

#6 Updated by Anna Maria Bigatti over 4 years ago

  • Subject changed from C++14: use the new for loop syntax where appropriate to C++14: use the new for loop syntax where appropriate (like cocoa's foreach)

Example: so I know where to find one ;-)

    for (const auto& f: GB)
      if (!IsSqFree(LPP(f))) return myAssignRadicalFlag(false);

#7 Updated by Anna Maria Bigatti about 4 years ago

  • % Done changed from 10 to 20

worked on TmpGReductor: much more readable!!!

#8 Updated by Anna Maria Bigatti about 4 years ago

  • Target version changed from CoCoALib-1.0 to CoCoALib-0.99800
  • % Done changed from 20 to 50

I looked for iterator and changed in a few more files. (can't remember which)
Not so many left to do.

#9 Updated by John Abbott about 4 years ago

I have changed some for loops to use the new syntax.
It is slightly worrying that one can change the code so easily without actually understanding what it does :-/
Anyway, the code still compiles, and all the tests pass...

I prefer to use auto only when the real type is "long and complicated": for example I find it clearer to write

  for (const RingElem& f: gens(I)) ...

rather than
  for (const auto& f: gens(I)) ...

The first form helps the reader (but the second form is easier to write if you do not really know the code).

NOTE I do agree that it usually makes the code much more readable :-)

#10 Updated by John Abbott about 4 years ago

  • % Done changed from 50 to 60

I have done the following files:

ApproxPts2.C
ApproxPts.C
ExternalLibs-Normaliz.C
GBEnv.C
QuotientRing.C
RingHom.C
TmpGReductor.C   (ONLY PARTLY?)
TmpIsTree.C
TmpJBAlgorithm.C
TmpJBDatastructure.C
TmpJBMill.C
TmpLDP.C
TmpPBMill.C
TmpStabilityAlgorithm.C
VectorOps.C

#11 Updated by John Abbott over 3 years ago

#12 Updated by John Abbott over 3 years ago

  • Related to Design #1520: Replace BOOST_FOREACH by new C++14 range for syntax added

#13 Updated by John Abbott about 2 years ago

  • Target version changed from CoCoALib-0.99800 to CoCoALib-0.99850

How should this be done in a systematic way (which can be paused)?
Postponing since it is just "tidying up".
We must try to remember to use the new syntax when writing new code!

#14 Updated by John Abbott about 1 year ago

  • % Done changed from 60 to 80

This is a mind-numbing task.
Something weird in SparsePolyOps-reduce.C:
the obvious transformation of the code seem not to work... no idea why!
I think more could still be done: there are lost of iterators in Mario Albert's code (phew!)

#15 Updated by John Abbott about 1 year ago

I have done some more. Anna fixed yesterday's bug.
Need a break from this... anyway it does seem to make the code more readable :-)

#16 Updated by John Abbott about 1 year ago

  • Target version changed from CoCoALib-0.99850 to CoCoALib-0.99880

#17 Updated by John Abbott 5 days ago

Some files still need tp be updated: I think the "morse" files need to be updated.
The "JB" files look to scary to touch!
Maybe TmpStability
I wouldn't do any more...
Any volunteers? Anna?

Also available in: Atom PDF