Idiomatic iterator for a linear function A while back, I asked a question about implementing an idiomatic iterator in C++. I've recently revisited the code, and I'm bothered by the duplication in the begin and end iterators. The code goes over a collection/iterator over a domain, and lazily produces the range using the iterator. After trimming down some code from the accepted answer, here's what I have:

class LinearFunction
{
public:
    LinearFunction(double m, double b) : m_(m), b_(b) { }

    double operator()(double x) const { return m_ * x + b_; }
private:
    double m_, b_;

};

template &lt;typename IterType&gt;
class LinearFunctionIterator
{
public:
    LinearFunctionIterator(IterType iter, LinearFunction const &amp;linearFunction)
        : xIter_(iter), linearFunction_(linearFunction) { }

    LinearFunctionIterator &amp;operator++() { 
        ++xIter_; 
        return *this;
    }

    double operator*() const {
        return linearFunction_(*xIter_);
    }

    bool operator!=(LinearFunctionIterator const &amp;other) const { 
        return xIter_ != other.xIter_;
    } 

private:
    IterType xIter_;
    LinearFunction linearFunction_; // &lt;--- (1)
};


template &lt;typename IterType&gt;
class LinearFunctionIteratorProxy
{
public:
    LinearFunctionIteratorProxy(IterType xBegin, IterType xEnd,
                                LinearFunction const &amp;linearFunction)
        : xBegin_(xBegin), xEnd_(xEnd), linearFunction_(linearFunction) { }

    LinearFunctionIterator&lt;IterType&gt; begin() const {
        return { xBegin_, linearFunction_ };
    }

    LinearFunctionIterator&lt;IterType&gt; end() const {
        return { xEnd_, linearFunction_ };
    }

private:
    IterType xBegin_, xEnd_;
    LinearFunction linearFunction_;
};


template&lt;typename Container&gt;
auto makeLinearFunction(Container const &amp;domain, 
                        LinearFunction const &amp;linearFunction) 
-&gt; LinearFunctionIteratorProxy&lt;decltype(std::begin(domain))&gt; 
{
    return { std::begin(domain), std::end(domain), linearFunction };
}


Usage:

#include "LinearFunction.h"
#include &lt;iostream&gt;
#include &lt;vector&gt;

int main()
{
    std::vector&lt;double&gt; domain { 1.0, 5.0, 2.0, 8.0 };
    LinearFunction linearFunction(10.0, 5.0);

    std::cout &lt;&lt; "Range:\n";
    for(auto rangeValue : makeLinearFunction(domain, linearFunction))
    {
        std::cout &lt;&lt; rangeValue &lt;&lt; ", ";
    }
}


What I'm looking for from the review:


Notice in the example usage, that there are three copies of the LinearFunction instance: one in the proxy, one in the begin iterator, and one in the end. Is there a better way to achieve the same behavior without this duplication? 
General advice to improve this code would be appreciated.
I suppose that if you don't really have a need to end member names with underscores, then you can avoid them.  Having similar names as constructor parameters won't even matter as long as you're using an initializer list.
Probably a bit nit-picky, but you may not need the precision of a double here.  If so, then you can just use floats.
With begin() and end(), you can also provide const versions (cbegin() and cend()).

Also, be careful with these names since they're also used in the STL.  You may also use slightly different names if you prefer.
If you really need operator!=, then you should also provide operator==.

In addition, it's usually preferred to define operator!= in terms of ==:

return !(xIter_ == other.xIter_);