Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Error in "NTL - moveable" documentation?
Error in "NTL - moveable" documentation? [message #4249] Sun, 30 July 2006 11:00 Go to next message
Werner is currently offline  Werner
Messages: 234
Registered: May 2006
Location: Cologne / Germany
Experienced Member
Unless I'm very much mistaken the SimpleVector template in "Browse topics - srcdoc - Core" cannot work:

When you instantiate the class the constructor sets capacity and items = 0.
When you add an item items is >= 0 and Expand is called.
Expand doubles capacity, but 2 * 0 still yields 0.
So capacity can never grow.

Although the example demonstrates what it is supposed to demonstrate, in my personal opinion it should be faultless - be it just for didactic reasons.

One possible solution might be:

void Expand()
{
    if (capacity == 0)
        ++capacity;
    else
        capacity *= 2;
    ...


Werner

[Updated on: Sun, 30 July 2006 11:04]

Report message to a moderator

Re: Error in "NTL - moveable" documentation? [message #4250 is a reply to message #4249] Sun, 30 July 2006 11:11 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Thanks!

Fixed: capacity = max(1, 2 * capacity);

Mirek
Re: Error in "NTL - moveable" documentation? [message #4295 is a reply to message #4250] Mon, 31 July 2006 21:19 Go to previous messageGo to next message
Werner is currently offline  Werner
Messages: 234
Registered: May 2006
Location: Cologne / Germany
Experienced Member
luzr wrote on Sun, 30 July 2006 11:11

Thanks!

Fixed: capacity = max(1, 2 * capacity);

Mirek


You're welcome!

May I suggest to check that "Expand" in the second - improved - "SimpleVector" class is also corrected?

There is another error - just a simple typo - in the "Moveable"-documentation:

The last member function of the class "SimpleString" is obviously the destructor, but the tilde (~) in front of "SimpleString" is missing.

By the way, the "Moveable" documentation leads to the following question:

As a "NTL_MOVEABLE"-macro example you provide:

NTL_MOVEABLE(std::string);


This provokes to use STL's "string" instead of UPP's "String". What is there against it? (After all its the standard!) Rolling Eyes

Werner
Re: Error in "NTL - moveable" documentation? [message #4297 is a reply to message #4295] Mon, 31 July 2006 23:28 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Werner wrote on Mon, 31 July 2006 15:19

luzr wrote on Sun, 30 July 2006 11:11

Thanks!

Fixed: capacity = max(1, 2 * capacity);

Mirek


You're welcome!

May I suggest to check that "Expand" in the second - improved - "SimpleVector" class is also corrected?

There is another error - just a simple typo - in the "Moveable"-documentation:

The last member function of the class "SimpleString" is obviously the destructor, but the tilde (~) in front of "SimpleString" is missing.

By the way, the "Moveable" documentation leads to the following question:

As a "NTL_MOVEABLE"-macro example you provide:

NTL_MOVEABLE(std::string);


This provokes to use STL's "string" instead of UPP's "String". What is there against it? (After all its the standard!) Rolling Eyes

Werner




Actually, this provokes that I should finally make the pass through NTL documentation.

NTL_MOVEABLE(std::string);

is unfortunately just a guessing - there is nothing in C++ standard about std::string being moveable and, worse, non-moveable implementation makes sense.

There are other troubles with std::string - e.g. copy may depend on the length. That is quite a problem as we are used to store whole files in String...

Mirek
Previous Topic: More String Functions [FEATURE REQUEST]
Next Topic: running programs from upp program
Goto Forum:
  


Current Time: Thu Mar 28 15:23:53 CET 2024

Total time taken to generate the page: 0.01383 seconds