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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:35:53+00:00 2026-06-14T12:35:53+00:00

I want to replace the BGL iteration over vertexes or edges with pure C++11

  • 0

I want to replace the BGL iteration over vertexes or edges with pure C++11 equivalent. The BGL code (from: http://www.boost.org/doc/libs/1_52_0/libs/graph/doc/quick_tour.html) is:

typename boost::graph_traits<Graph>::out_edge_iterator out_i, out_end;
typename boost::graph_traits<Graph>::edge_descriptor e;
for (std::tie(out_i, out_end) = out_edges(v, g);
     out_i != out_end; ++out_i)
{
  e = *out_i;
  Vertex src = source(e, g), targ = target(e, g);
  std::cout << "(" << name[get(vertex_id, src)]
            << "," << name[get(vertex_id, targ)] << ") ";
}

I tried several suggestions from here: Replace BOOST_FOREACH with "pure" C++11 alternative? but without luck.

I want to be able to write something like:

for (auto &e : out_edges(v, g))
{ ... }

or something like:

for (std::tie(auto out_i, auto out_end) = out_edges(v, g);
     out_i != out_end; ++out_i)
{...}

Is it possible?

  • 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-14T12:35:54+00:00Added an answer on June 14, 2026 at 12:35 pm

    A simple wrapper over out_edges should suffice:

    #include <boost/range/iterator_range.hpp>
    #include <type_traits>
    
    template<class T> using Invoke = typename T::type
    template<class T> using RemoveRef = Invoke<std::remove_reference<T>>;
    template<class G> using OutEdgeIterator = typename boost::graph_traits<G>::out_edge_iterator;
    
    template<class V, class G>
    auto out_edges_range(V&& v, G&& g)
      -> boost::iterator_range<OutEdgeIterator<RemoveRef<G>>>
    {
      auto edge_pair = out_edges(std::forward<V>(v), std::forward<G>(g));
      return boost::make_iterator_range(edge_pair.first, edge_pair.second);
    }
    

    Or even simpler, a function that turns a std::pair into a valid range:

    template<class It>
    boost::iterator_range<It> pair_range(std::pair<It, It> const& p){
      return boost::make_iterator_range(p.first, p.second);
    }
    

    and then

    for(auto e : pair_range(out_edges(v, g))){
      // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to replace Demo image by code css3 or somthing else. I have
I want to replace backslash => '\' with secure &#92; replacement. But my code
I Want Replace String ':' by '/', I am Using this code to replace
I have this code, and I want to know, if I can replace only
I want to replace the code snippet between two custom tag (@Start, @End) with
I want to replace child elements from one tree to another , based on
hello I want replace following phrase: tinymce/jscripts/tiny_mce/plugins/emotions/img/smiley-cool.gif with: http://mysite.com/tinymce/jscripts/tiny_mce/plugins/emotions/img/smiley-cool.gif I have tried : $comments
i have the following code.My table is called 'tableu'.I want replace 'tableu' with a
I want to extract variables from math expression using c#. I wrote this code
I want to replace all the url's which are starting with something like www.sitename.com/xxx/xxx.html

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.