1

I am not able to get this to work:

template<class Input, class Output, class Index>
size_t pack(void (*copy)(Input, Input, Output),
            size_t N, Input input, Output output,
            const Index &index);

size_t K = pack(&std::copy<const double*,double*>,
                M, C.data().begin(), C_.data().begin(),
                index.host);

compiler message I get tells me that copy is not resolved, instead I get unresolved overloaded function type>.

what am I doing wrong? thank you

2
  • 1
    bummers, I found problem, std::copy returns output not void. Should I delete this question? Commented Jul 27, 2010 at 3:27
  • You can write then accept your own answer. Better than deletin'. Commented Jul 27, 2010 at 3:37

2 Answers 2

2

well, I missed return type of std::copy which is output iterator type.

Correct code :

template<class Input, class Output, class Index>
size_t pack(Output (*copy)(Input, Input, Output),
            size_t N, Input input, Output output,
            const Index &index);
Sign up to request clarification or add additional context in comments.

Comments

1

You could make a design change. One might be make the return type a separate template parameter:

template<class R, class Input, class Output, class Index>
size_t pack(R (*copy)(Input, Input, Output),
            size_t N, Input input, Output output,
            const Index &index);

The return type is deduced (and subsequently ignored by your code.) The other option, which I would recommend, would be to accept any generic function type:

template<class CopyFunc, class Input, class Output, class Index>
size_t pack(CopyFunc func,
            size_t N, Input input, Output output,
            const Index &index);

This doesn't enforce any specific signature, and provides the most flexibility.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.