To get started, I have something like this:
class Test { std::vector<int> a, b; void caller(...) { callee(...); } void callee(...) { } }
I would like to have a function that does the same thing as callee , but for vector b . There are two obvious solutions for this:
- pass vector
a or b as an argument. However, callee is a recursive function that can be used for hundreds of calls, and wrapping vectors as arguments is just an extra overhead. - Copy the
callee function and use the vector b , which would be a better alternative, even though callee is a rather long function and I will have a lot of duplicate code.
Out of curiosity, I went to search for a part of the templates, and I noticed what can be used for
reference value type
pointer type
member type pointer
So I tried to do this:
class Test { std::vector<int> a, b; void caller(...) { callee<a>(...); } template <std::vector<int> &x> void callee(...) { } }
but i get
error: using 'this in constant expression
Is there a way to achieve this with either a link or a pointer?
By the way, what I want can be seen as a scope of #define functions
source share