Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
UppHub
Status & Roadmap
FAQ
Authors & License
Forums
Funding U++
Search on this site











SourceForge.net Logo

SourceForge.net Logo

GitHub Logo

Discord Logo

Rules for references to ValueArray, ValueMap and Value elements

Value is originally designed as non-mutable concrete Value of different concrete types.

 

However, as Value is commonly used to store complex hierarchies (using ValueArray/ValueMap), it is in the end very useful to be able to reference ValueArray/ValueMap elements directly. Validity of such references is restricted by following rule:

 

Reference obtained from Value/ValueArray/ValueMap (by Value::At, Value::GetAdd, ValueArray::At, ValueMap::GetAdd and derivative methods) are only valid until the next operation on originating Value - including just reading it.

 

Examples of invalid code:

 

 

Value m;

Value& x = m("key");

x = m; // using m as source invalidates x

....

Value m;

Value& x = m("key");

Value& y = m("key2"); // Invalidates x

x = 123; // undefined

....

Value m;

Value& x = m.At(1);

Value m2 = m; // Invalidates x

x = "fail"; // undefined

 

Do you want to contribute?