Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext
value_stack::push_object

Push an object formed by popping n key/value pairs from the stack.

Synopsis
void
push_object(
    std::size_t n);
Description

This function pushes an object value onto the stack. The object is formed by first popping the top n key/value pairs from the stack. If the stack contains fewer than n key/value pairs, or if any of the top n key/value pairs on the stack does not consist of exactly one key followed by one value, the behavior is undefined.

Remarks

A key/value pair is formed by pushing a key, and then pushing a value.

Example

The following code creates an object on the stack with a single element, where key is "x" and value is true:

value_stack st;

// reset must be called first or else the behavior is undefined
st.reset();

// Place a key/value pair onto the stack
st.push_key( "x" );
st.push_bool( true );

// Replace the key/value pair with an object containing a single element
st.push_object( 1 );

// Pop the object from the stack and take ownership.
value jv = st.release();

assert( serialize(jv) == "{\"x\",true}" );

// At this point, reset must be called again to use the stack
Duplicate Keys

If there are object elements with duplicate keys; that is, if multiple elements in an object have keys that compare equal, only the last equivalent element will be inserted.

Parameters

Name

Description

n

The number of key/value pairs to pop from the top of the stack to form the array.


PrevUpHomeNext