Boost logo

Boost :

From: Robert Jones (robertgbjones_at_[hidden])
Date: 2008-08-04 10:40:04


I have had some time recently to look through some of the Boost source code,
and am finding it an absolute treasure trove of useful techniques and
idioms. I'd just
like to check out my understanding of afew things, and would appreciate
feedback.

In spirit\home\phoenix\stl\algorithm\transformation.hpp is this

namespace boost { namespace phoenix { namespace impl
{
    struct swap
    {
        template <class A, class B>
        struct result
        {
            typedef void type;
        };

        template <class A, class B>
        void operator()(A& a, B& b) const
        {
            using std::swap;
            swap(a, b);
        }
    };
...

Am I correct in thinking that the purpose of this is is too present swap as
a 'well-behaved'
functor from a phoenix composition point of view, with a nested type member?

Also in this snippet, the function operator does 'using std::swap;' then
uses 'swap' without
quaification, rather than explicitly invoking std::swap. The effect of this
(I assume) is
to perform full name resolution on swap. Why is this done for swap, but not
for any other
std identifiers, eg copy?

Elsewhere in spirit\home\phoenix\stl\algorithm\detail\begin.hpp is this...

namespace boost { namespace phoenix {
namespace detail
{
  template<class R>
  typename range_result_iterator<R>::type
  begin_(R& r)
  {
      return boost::begin(r);
  }
}
}}

This seems to do nothing other than provide an 'indirection' to calling
boost::begin. Is the purpose
here to provide a possible opportunity for specialisation?

It is, btw, a real pleasure to have the chance to see the code of genuine
experts in the
field.

Thanks in advance, Rob


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