Boost logo

Boost :

From: jsiek_at_[hidden]
Date: 2000-01-27 00:46:50


Dave Abrahams writes:
> > Or with g++, even if you don't do a "using anmespace std;", the
> > conflict still happens :( The only way to avoid it would be to say
> > set() has to be in boost, and always do boost::set(), which is
> > a bit nasty.
>
> What is nasty about that?

Well, it means *everyone* has to put their property accessors in
namespace boost, and it clutters up your algorithm code. It
was bad enough moving away from operator[] to set/get, but
boost::set, boost::get is even worse! Check out the following
algorithm, which version is more readable?

On a side note, checkout how cool the expression-template'd
functors work in this example :)

template <class F, class PredGraph, class In, class Out>
void
iterate_flow_forward( const F& f,
                      const PredGraph& blocks,
                      In in,
                      Out out )
{
  typename graph_traits<PredGraph>::adjacency_iterator p, pend;
  typedef typename std::iterator_traits<In>::value_type Set;
  bool change;
  int B;
  do {
    change = false;
    for (B = 0; B < num_vertices(blocks); ++B) {
      tie(p, pend) = inv_adj(B, blocks);
      boost::set(in, B, accumulate(p, pend, Set(),
                                   identity<Set>() + indirect(out)));
      Set old_out = boost::get(out, B);
      boost::set(out, B, f(B, boost::get(in, B)));
      if (boost::get(out, B) != old_out)
        change = true;
    }
  } while (change);
}

template <class F, class PredGraph, class In, class Out>
void
iterate_flow_forward( const F& f,
                      const PredGraph& blocks,
                      In in,
                      Out out )
{
  typename graph_traits<PredGraph>::adjacency_iterator p, pend;
  typedef typename std::iterator_traits<In>::value_type Set;
  bool change;
  int B;
  do {
    change = false;
    for (B = 0; B < num_vertices(blocks); ++B) {
      tie(p, pend) = inv_adj(B, blocks);
      in[B] = accumulate(p, pend, Set(), identity<Set>() + indirect(out));
      Set old_out = out[B];
      out[B] = f(B, in[B]);
      if (out[B] != old_out)
        change = true;
    }
  } while (change);
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk