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 7746559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:18:36+00:00 2026-06-01T10:18:36+00:00

Does Boost Ranges have a built-in way to cout the elements easily, for example

  • 0

Does Boost Ranges have a built-in way to cout the elements easily, for example separated by comma or space?

I am of course aware that I could loop over them and print them separately, but it seems to me that this should be built in somehow (like printing a vector in scripting languages).

In an example program I saw, the author copied the range to cout:

boost::copy(range, ostream_iterator(cout, ” “))

Looks ugly to me. Is this idiomatic?

EDIT: A solution for std iterators would also be acceptable.

EDIT2:
What I want to do is this:

cout << range;

But I don’t think that works.
So what I am hoping for is something like this (Python inspired):

cout << range.join(", ");

or perhaps with a range adaptor.

cout << (range | stringify(", "));
  • 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-06-01T10:18:37+00:00Added an answer on June 1, 2026 at 10:18 am

    I don’t believe it’s ever been really finished/polished, but that’s the intent of Boost.Explore.

    Personally, I’ve just gotten used to using std::copy. For this sort of thing, an infix_ostream_iterator can be quite helpful at times. For example, something like this:

    #include <vector>
    #include <iostream>
    #include <algorithm>
    #include <iterator>
    #include "infix_iterator.h"
    
    template <typename T>
    std::ostream& operator<<(std::ostream &o, const std::vector<T>& v) { 
        o << "[";
        std::copy(v.begin(), v.end(), infix_ostream_iterator<T>(o, ", ")); 
        o << "]";
        return o; 
    }
    
    int main() { 
    
        std::vector<int> x;
    
        for (int i=0; i<20; i+=2)
            x.push_back(i);
    
        std::cout << x << "\n";
        return 0;
    }
    

    As it stands, this has operator<< taking a vector, but it would be relatively trivial to have it take a range instead.

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

Sidebar

Related Questions

Does calling a destructor of an boost::lock object explicitly have any consequence at all?
Does boost have one? Where A, y and x is a matrix (sparse and
Does C++ standard library and/or Boost have anything similar to the filter function found
What is std::pair for, why would I use it, and what benefits does boost::compressed_pair
How does one use boost::spirit with an input that consists of something other than
Does anyone know if there's a de-facto standard (i.e., TR1 or Boost) C++ function
The following does not compile: class Foo { public: Foo( boost::shared_ptr< Bar > arg
Why does nobody seem to use tuples in C++, either the Boost Tuple Library
Why does the following code not allow foo(ptr) to be called ? #include <boost/scoped_ptr.hpp>
What is the purpose of using the Boost.MPI library? Does it increase performance? And

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.