COIN-OR::LEMON - Graph Library

Opened 4 years ago

Last modified 17 months ago

#466 new enhancement

Extended std::vector<>

Reported by: alpar Owned by: alpar
Priority: major Milestone: LEMON 1.5 release
Component: core Version: hg main
Keywords: Cc:
Revision id:

Description

Based upon the idea of #462.

We could implement a wrapper around std::vector<> with the following two extra features.

  • A extra permanent iterator. It has the same functionality as std::vector::iterator but remains valid even when the vector is extended by new elements. Technically, it contains a pointer to the base vector plus an index.
  • An index type. In non-debug mode it is just a size_t, but in debug mode it also contains a pointer to the vector it indexes, thus operator[]() is able to check if the index indexes the right vector (and also if it is in the actual range).

Both would be safer alternatives to referencing std::vector<>'s elements by integer indices.

Attachments (1)

466.diff (16.2 KB) - added by r0mai 3 years ago.
Implementation of safe_vector

Download all attachments as: .zip

Change History (3)

comment:1 Changed 4 years ago by alpar

The point is that I'm just debugging a code which uses many std::vector<>s and (integer) cross references between them and does something wrong. If we used one of the features above for cross referencing, it would immediately locate the root of the problem.

Changed 3 years ago by r0mai

Implementation of safe_vector

comment:2 Changed 17 months ago by alpar

  • Milestone changed from LEMON 1.4 release to LEMON 1.5 release
Note: See TracTickets for help on using tickets.