Boost logo

Boost Users :

From: Kosta (boost_at_[hidden])
Date: 2005-03-22 02:22:46


The problem is not boost specific, but probably there is a boost specific
solution to it...

The usual way of passing and returning elements to/from a function/method is
to use a templated function/method, e.g.:

template<
    typename ITER_IN,
    typename ITER_OUT
>
void doSomething(
    ITER_IN inBegin,
    ITER_IN inEnd,
    ITER_OUT outIter,
    int param1, int param2, ...
) {
    while(inBegin != inEnd) {
        ...
        *outIter++ = ...;
    }
}

But what to do in case of (pure) virtual methods which can't be templated?
One (neither pretty nor efficient) solution would be something like this:

struct A {
    template<typename ITER_IN, typename ITER_OUT>
    void doSomething(
        ITER_IN inBegin,
        ITER_IN inEnd,
        ITER_OUT outIter,
        int param1, int param2, ...
    ) {
        const std::vector<int> out(
            doSomething_impl(
                std::vector<int>(inBegin, inEnd), param1, param2
            )
        );
        std::copy(out.begin(), out.end(), outIter);
    }

    virtual std::vector<int> doSomething_impl(
        std::vector<int>& const in,
        int param1, int param2, ...
    ) = 0;

}; // struct A

Is there a better (boost-ish) solution?


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net