$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: John E. Potter (jpotter_at_[hidden])
Date: 2000-12-31 20:44:37
On Fri, 29 Dec 2000, Arun Sivaramakrishnan wrote:
> Jeremy wrote:
> >
> > If you want to use a function returning a reference, use projection
> > iterator instead of transform.
>
> Same problem.
Not really. Transform has value semantics and projection has reference
semantics.
> Since we cannot have pointer to references or reference to references
> there are compiler errors when AdaptableUnaryFunction
> returns a reference type.
> As Dave said, we do need specializations to overcome this problem
> atleast for some compilers.
This is a lack of documentation. Projection_iterator has reference
semantics always. There is a general problem with reference template
parameters. Vector<int&>? Set<int&>? They just don't work. But,
struct RefFunc : public unary_function<SomeThing, int> {
int& operator() (SomeThing& st) { return st.someIntField; }
};
works fine with both std::unary_function and projection_iterator. It
is a lie which works well. The only purpose of std::unary_function is
to extract the correct value_type. Reference and pointer are always
value_type& and value_type*. The function object must have reference
semantics.
Improvements welcome. It could make transform and projection one
iterator.
John