Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Serializing stacks

35 views
Skip to first unread message

woodb...@gmail.com

unread,
Mar 8, 2017, 1:40:45 PM3/8/17
to
Shalom

I was thinking about adding serialization support for plf::stack
to my on line code generator. But in looking into the interface
for this container: http://plflib.org/stack.htm

and std::stack: http://www.cplusplus.com/reference/stack/stack/

it seems that neither of them permit the telepathic kinesis needed
for serialization. As a morally straight boy scout, I'd like to
be prepared for the case where someone wants to marshal a stack
between programs.

I didn't check, but possibly the same problem exists for std::queue.
Any thoughts on how to approach this? Thanks in advance.


Brian
Ebenezer Enterprises - In G-d we trust.
http://webEbenezer.net

Alf P. Steinbach

unread,
Mar 8, 2017, 3:53:52 PM3/8/17
to
On 08-Mar-17 7:40 PM, woodb...@gmail.com wrote:
> Shalom
>
> I was thinking about adding serialization support for plf::stack
> to my on line code generator. But in looking into the interface
> for this container: http://plflib.org/stack.htm
>
> and std::stack: http://www.cplusplus.com/reference/stack/stack/
>
> it seems that neither of them permit the telepathic kinesis needed
> for serialization.

You can serialize a `std::stack` by accessing the protected container
member.

One way to access it is by using a member data pointer.

#include <iostream>
#include <stack>

template< class Item, class Container >
auto container_of( std::stack<Item, Container> const& st )
-> Container const&
{
struct Access: std::stack<Item, Container>
{
using std::stack<Item, Container>::c;
};

return st.*&Access::c;
}

auto main()
-> int
{
std::stack<int> st;
for( const int v : { 3, 1, 4, 1, 5, 9 } ) { st.push( v ); }

for( int const v : container_of( st ) )
{
std::cout << v << "\n";
}
}

> As a morally straight boy scout, I'd like to
> be prepared for the case where someone wants to marshal a stack
> between programs.
>
> I didn't check, but possibly the same problem exists for std::queue.

Same solution.


Cheers & hth.,

- Alf

woodb...@gmail.com

unread,
Mar 9, 2017, 5:59:27 PM3/9/17
to
OK, I understand some of that, but if the claim that plf::stack
generally out-performs std::stack:

"Simply put, plf::stack out-performs both std::stack (std::deque)
and std::vector once you take into account both push and pop time,
and we can see that the larger the stored type is, the greater
the performance advantage is."

is true, it's the container I'd rather focus on. It's not clear
to me if adding interfaces to support serialization would somehow
compromise his implementation/test results.


Brian
Ebenezer Enterprises
http://webEbenezer.net
0 new messages