Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 592959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:47:41+00:00 2026-05-13T15:47:41+00:00

Note: Edited based on responses to receive more appropriate answers. I have a collection

  • 0

Note: Edited based on responses to receive more appropriate answers.

I have a collection of C++ templates that I’ve made over the years, which I call Joop. It comprises mainly libraries that don’t quite fall into the “general-purpose” category but are just useful enough that I keep slapping them into different projects, so most of them don’t have equivalents in other libraries such as Boost.

One of these classes is seqstream. The idea is that it allows you to treat any iterable sequence as an ordinary STL-like stream, whose “character type” is the value type of the sequence.

The rationale for this class is twofold. First, it should present an interface that makes any potentially nonlinear, noncontiguous sequence look linear and contiguous; and second, it should treat any object in the stream as though it were a single, complex, large character. There is a standard means of treating a stream as a sequence, so why not the other way around?

At present, seqstream wraps three iterators for the first, last, and current element. I want to replace seqstream with a basic_seqbuf that can be plugged into a standard stream. Can anyone provide resources to get me started on extending std::basic_streambuf to provide this kind of behaviour?

Additionally, if a writable seqbuf is allowed, it is very that writing an object to the seqbuf does not serialise the object, but makes the appropriate call to an insert() method or uses a user-specified insert iterator, such as a std::back_insert_iterator.

Edit:

Here is an example of how seqstream is currently used:

// Create a sequence of objects.
std::vector<std::string> sequence;
for (int i = 0; i < 10; ++i) {
    std::ostringstream stream;
    stream << "Element " << i << ".";
    sequence.push_back(stream.str());
}

// Create a seqstream wrapping that sequence.
joop::seqstream< std::vector<std::string> > seqstream(sequence.begin(), sequence.end());

// Read the sequence like a stream.
std::string element;
while (seqstream >> element) // OR seqstream.get(element)
    std::cout << element << '\n';
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:47:41+00:00Added an answer on May 13, 2026 at 3:47 pm

    It can be confusing to look at the examples in sstream, but you probably don’t want a new stream class at all. Looking now for an example at the basic_stringstream source, the only purpose of that class is to

    • provide str function (it just calls the underlying buffer’s str)
    • avoid the underlying buffer’s vtable when calling its methods
    • change rdbuf‘s return value to basic_stringbuf* (but that’s unnecessary because an accessor for str was provided)

    The stream classes do very little, and really aren’t supposed to have any functionality besides calling an underlying buffer of type basic_streambuf. For example, I can do this:

    string str( "Hello, world!" );
    stringbuf buf( str ); // subclass of basic_streambuf
    iostream pseudo_stringstream( &buf );
        // pseudo_stringstream can do anything a stringstream can do.
        // (not necessarily with the same syntax)
    

    Moreover, all streams are supposed to inherit from either basic_istream, basic_ostream, or both. Inserter/extractor functions may not work if your stream doesn’t inherit correctly. These inserter declarations are perfectly fine:

    operator<<( ostream os, MyData d ); // not a template at all
           // templated, but requires correct inheritance:
    template< class C > operator<<( basic_ostream<C> os, MyData d );
    

    Therefore, if you want iostream behavior, you need to implement a subclass of basic_streambuf and attach it to a basic_iostream.


    But, what is your actual goal? What is the advantage of a memory-backed stream over the usual iterators and maybe some back_insert_iterators? Do you want to use the same code for serialization as for iteration? You probably want to make the stream look like a sequence using stream_iterator, not to make the sequence look like a stream.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

NOTE: EDITED The real-world situation is a series of events that each have two
I have a old command line based program (its fortran if that matters) that
Note: i edited my Q (in the title) so that it better reflects what
[Editor's note: I have edited the title to try to make this useful to
I have a edited RESTful wizard based upon Shoulders of Giants | A RESTful
Note: question has been edited to stay in sync with what I have tried
NOTE: Edited to add the Model The Problem: a querystring guid value is giving
Note that I am not asking which to choose (MVC or MVP), but rather
(Note: This is for MySQL's SQL, not SQL Server.) I have a database column
To provide an activity log in my SQLAlchemy-based app, I have a model like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.