
This solves my problem, thanks!
"Steven Watanabe"
AMDG
Roberto Gimenez wrote:
I need something like this:
template <typename Type> struct Array;
But I think boost doesn't have it. boost::array also takes an std::size_t template parameter but that doesn't work for what I want to do because I want to be able to pass a function something like this:
void myFunction(const Array<int> &a) { ... }
void main() {
int myVec1[6] = { 1,2,3,4,5,6 }; int myVec2[2] = { 7,8 };
myFunction(Array<int>(myVec1, 6)); myFunction(Array<int>(myVec2, 2));
}
I can't do this with boost::array and std::vector allocates and I don't want that too. Any help?
You can use iterator_range.
#include
#include <iostream> #include <algorithm> typedef boost::iterator_range
int_array; void myFunction(const int_array &a) { std::copy(a.begin(), a.end(), std::ostream_iterator<int>(std::cout, " ")); }
int main() { int myVec1[6] = { 1,2,3,4,5,6 }; int myVec2[2] = { 7,8 };
myFunction(int_array(myVec1, myVec1 + 6)); myFunction(int_array(myVec2, myVec2 + 2)); }
In Christ, Steven Watanabe