Suppose that I have an arbitrary template method that could receive parameters by value and by reference const (obviously, for trivial types and for objects, respectively).
How is this situation handled when writing prototype templates?
I could do something like:
template <typename T> void Foo(T value) {
}
template <typename T> void Foo(const T& value) {
}
template <> void Foo<int>(int value) { }
template <> void Foo<Object>(const Object& value) { }
But this approach is only suitable for trivial functions that act as a wrapper for some other calls.
If a function (not a templated version) contains a lot of code inside it, it means that I would have to copy the code twice.
Can I do something smarter here?
source
share