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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:02:05+00:00 2026-06-08T06:02:05+00:00

Here is an example of a range adaptor based off of Implement a Range

  • 0

Here is an example of a range adaptor based off of Implement a Range Adaptor with arguments:

#include <boost/range/join.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/iterator/permutation_iterator.hpp>
#include <vector>
#include <list>
#include <iterator>
#include <iostream>

template <typename Range, typename Index>
class permutation_range :
        public boost::iterator_range<
                boost::permutation_iterator<
                        typename boost::range_iterator<Range>::type,
                        typename boost::range_iterator<Index>::type>>
{
    using value_type = typename boost::range_value<Range>::type;
    using replaced_iterator = boost::permutation_iterator<
                            typename boost::range_iterator<Range>::type,
                            typename boost::range_iterator<Index>::type>;
    using base_t = boost::iterator_range<replaced_iterator>;
public:
    permutation_range(Range& r, Index& i)
            : base_t(replaced_iterator(boost::begin(r), boost::begin(i)),
                    replaced_iterator(boost::end(r), boost::end(i)))
    {}
};

template <typename Range, typename Index>
permutation_range<Range, Index>
permutation(Range& r, Index& i)
{
    return permutation_range<Range, Index>(r, i);
}

int main()
{
    std::vector<int> v1{99, 1, 99,  2, 99, 3};
    std::list<int> indexer{1, 3, 5};
    boost::copy(permutation(v1, indexer),
                std::ostream_iterator<int>(std::cout, " "));
}

Output

1 2 3

I want to adapt the above to use boost::joined_range. In other words, take two vectors and then join them into one longer range inside of permutation_range. The idea is simple:

Example which would output 2 4 6:

int main()
{
    std::vector<int> v1{1, 2, 3};
    std::vector<int> v2{4, 5, 6};
    std::list<int> indexer{1, 3, 5};
    boost::copy(permutation(v1, v2, indexer),
                std::ostream_iterator<int>(std::cout, " "));
}

All my attempts so far have ended in a huge list of compiler errors, I haven’t showed the attempts because I may be way off. I don’t know if it is possible, but could anyone help me out here?

FINAL EDIT (Solution with a little hack to get the range initialized before the base class)

#include <boost/range/join.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/iterator/permutation_iterator.hpp>
#include <vector>
#include <list>
#include <iterator>
#include <iostream>

template <typename R1, typename R2>
struct initialize_me_first
{
    initialize_me_first(typename boost::range::joined_range<const R1, const R2> j)
    : j_range(j)
    {}
    typename boost::range::joined_range<const R1, const R2> j_range;
};

template <typename Range1, typename Range2, typename Index>
class permutation_range :
        public initialize_me_first<Range1, Range2>,
        public boost::iterator_range<
                boost::permutation_iterator<
                        typename boost::range_iterator<
                            boost::range::joined_range<Range1, Range2>>::type,
                        typename boost::range_iterator<Index>::type>>
{
    using value_type = typename boost::range_value<Range1>::type;
    using replaced_iterator = boost::permutation_iterator<
                    typename boost::range_iterator<
                            boost::range::joined_range<Range1, Range2>>::type,
                            typename boost::range_iterator<Index>::type>;
    using base_t = boost::iterator_range<replaced_iterator>;
    using init = initialize_me_first<Range1, Range2>;
public:
    permutation_range(const Range1& r1, const Range2& r2, const Index& i)
            : init(boost::join(r1, r2)),
              base_t(replaced_iterator(boost::begin(init::j_range),
                                       boost::begin(i)),
                    replaced_iterator(boost::end(init::j_range),
                                       boost::end(i)))
    {}
};

template <typename Range1, typename Range2, typename Index>
permutation_range<const Range1, const Range2, const Index>
permutation(const Range1& r1, const Range2& r2, const Index& i)
{
    return permutation_range<const Range1,
                             const Range2,
                             const Index>(r1, r2, i);
}

int main()
{
    std::vector<int> v1{1, 2, 3};
    std::vector<int> v2{4, 5, 6};
    std::list<int> indexer{1, 3, 5};
    boost::copy(permutation(v1, v2, indexer),
                std::ostream_iterator<int>(std::cout, " "));
}
  • 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-08T06:02:06+00:00Added an answer on June 8, 2026 at 6:02 am

    To join two ranges, use boost::join:

    #include <boost/range/join.hpp>
    
    boost::copy(permutation(boost::join(v1, v2), indexer), ...
    

    But change your Range parameters to be passed by const reference instead of non-const reference. There’s no reason to require modifiable versions of those arguments since you’re not actually permuting their contents.

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

Sidebar

Related Questions

Here is example which I have try <?php include 'spider/classes/simple_html_dom.php'; $html = new simple_html_dom();
Based on example found here but I guess I'm not understanding it. This works
I'm attempting to implement the technique for data validation from Josh Smith's example here:
I know it can denote range, but for example here [-.\d] seems like this
Here an example http://jsfiddle.net/EhLsT/ $(window).scroll(function () { if ($(window).scrollTop() > $(#header).offset().top) { $(#floating).show(); }
Here an example http://jsfiddle.net/7aVXc/ Let' say current image height is 400px . How do
Here an example http://jsfiddle.net/NuzDj/ If you resize windows size, sidebar overlapping the wrapper &
Example: here is the string: blablabla123:550:404:487blablabla500:488:474:401blablablabla here is what I'm using: string reg =
Example here: http://jezebel.com/5896408/racist-hunger-games-fans-dont-care-how-much-money-the-movie-made Click on the 3x3 Tweets screencap they have up. I love
The fictional example here. Suppose I designed a class named IODevice. This class already

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.