Opened 13 years ago

Closed 13 years ago

#515 closed discussion (wontfix)

Why isn't theplu::yat::utility::Index a derived class of std::vector<size_t>?

Reported by: Jari Häkkinen Owned by: Jari Häkkinen
Priority: major Milestone:
Component: utility Version: 0.5.2
Keywords: Cc:

Description (last modified by Jari Häkkinen)

I need push_back and reserve functionality ... but the Index class does not support that.

I'd like to create a Index for use with MatrixLookup but I do not know the length of the Index. Now I have to create a std::vector<size_t> first and then initialize the Index.

Is there any good reason to not derive Index from std::vector?

Change History (5)

comment:1 Changed 13 years ago by Jari Häkkinen

Description: modified (diff)

comment:2 Changed 13 years ago by Peter

The short answer is that copy in Index is shallow (only a vector<size_t>*) is copied. Consequently multiple Index can have a pointer to the same vector and to simplify the implementation we did not allow any non-constness in the interface.

Of course, we could allow non-constness and change to copy-on-write, but I do want to keep the copy as shallow as possible. (That was the reason Index replaced vector<size_t> in the Lookups).

comment:3 Changed 13 years ago by Jari Häkkinen

The documentation is saying

theplu::yat::utility::Index::Index(const std::vector< size_t >& vec) [explicit]


vec is copied 

be changed then? It should say the vec cannot go out of scope ... which it does in my code.

comment:4 Changed 13 years ago by Peter

Sorry for being unclear. The documentation is correct. The vector is copied in the constructor you refer to.

I was talking about copying an Index from another Index, in which case a shallow reference counted copy is performed.

comment:5 Changed 13 years ago by Peter

Milestone: yat 0.x+
Resolution: wontfix
Status: newclosed
Note: See TracTickets for help on using tickets.