[phoenix] Explanation of some standard idioms

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

AMDG Robert Jones wrote:
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?
Yes.
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?
In other cases, such as copy, we usually intend to call the standard function. By calling std::copy explicitly, we make sure that we are calling the function that we intend to. Many types have an overloaded swap, which can be found by ADL. Usually this swap is more efficient than the default implementation in namespace std. We want to call this swap if it is present.
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?
begin_ doesn't seem to be intended for specialization/overloading. (It's in namespace detail and nothing in spirit specializes it) I have no idea what it is for. It may just be a relict of an earlier version. In Christ, Steven Watanabe
participants (2)
-
Robert Jones
-
Steven Watanabe