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

  • Home
  • SEARCH
  • 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 4265238
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:35:49+00:00 2026-05-21T06:35:49+00:00

Boost’s any_range documentation says the following: Despite the underlying any_iterator being the fastest available

  • 0

Boost’s any_range documentation says the following:

Despite the underlying any_iterator being the fastest available implementation, the performance overhead of any_range is still appreciable due to the cost of virtual function calls required to implement increment, decrement, advance, equal etc. Frequently a better design choice is to convert to a canonical form.

What does the author mean by a "canonical form"? Can someone give an example?

EDIT: As suggested here, I asked the same question on the boost users’ mailing list. Here is what Neil Groves, the original author of this text had to say:

For example, copying the range into a vector.

Yes, this is exactly the alternative design that I had in mind when writing the documentation. The overhead of iterating over an any_range is quite considerable, and often compares poorly with copying a concrete result-type into a container such as a vector. However, this is not always the case and some of the users of Boost.Range have desired the ability to implement algorithms that operate upon any_range instances. This is sometimes desirable to allow, for example, exposure of algorithms from a shared library that supports various containers. The use of any_range may also make sense where the number of passes over the range are small, but the memory size of the underlying container is very large.

In many cases, the performance overhead will not matter. I wanted to ensure that I did not mislead anyone into the widespread adoption of any_range usage. I believe that the valid usages for this class are few, but sometimes it is exactly the correct design choice. I shall improve the documentation with some additional clarification and examples in due course.

  • 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-21T06:35:49+00:00Added an answer on May 21, 2026 at 6:35 am

    I think they mean converting your range to an std::vector, or whatever the standard container is in your project, and returning an iterator into that.

    The tradeoff is between the cost of making a copy of your range from the original range type to the canonical container type, and the cost of heap allocations and virtual function calls associated with the type erasure used to implement any_range. Depending on how many elements are in the range, how large each element is, and how many passes will be made over the range, one option may be better than the other.

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

Sidebar

Related Questions

Boost's C99 stdint implementation is awfully handy. One thing bugs me, though. They dump
Boost is meant to be the standard non-standard C++ library that every C++ user
Boost is a very large library with many inter-dependencies -- which also takes a
Boost is a great set of libraries and it really boosts productivity. But debugging
When the Boost library/headers is used with VC++ 9 compilers (Visual C++ 2008 Express
I'm considering dumping boost as a dependency... atm the only thing that I really
I use the Boost Test framework for my C++ code but there are two
How do you install Boost on MacOS? Right now I can't find bjam for
I have a Boost unit test case which causes the object under test to
I use RCF with boost.serialization (why use RCF's copy when we already use the

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.