I am using VS2008 compatible code with Boost 1.60 (no C++ 11). I have a third party library that returns a list-like interface. I want to take the elements of the list and put them in an std::vector. The track_list class has a next method which returns a pointer to a track pointer track**.
I was thinking I could use std::generate to fill a vector the same size as the track_list. I was able to come up with boost::bind(&track_list::next, tracks) which gets me the track** but I am not sure how to add the dereferencing part to get the track* to go into the vector<track*>.
Furthermore, there's actually a specific_track* that I know is safe to cast to from track*. So what I am really looking for is something along the lines of (specific_track*)(*boost::bind(&track_list::next, tracks)) but I am not sure how to construct that syntactically. Am I on the right track? I looked at boost lambdas but the generator function takes no arguments.
Edit: maybe a simpler example might help with clarifying exactly what I'm trying to do.
int** get_ptr_num() { int* i = new int(5); return new int*(i); }
int* get_num() { return new int(5); }
int main() {
std::vector<int*> nums(10);
std::generate(nums.begin(), nums.end(), get_num) // compiles
std::generate(nums.begin(), nums.end(), get_ptr_num) // cannot convert from int** to int*
}
Basically I just want to wrap get_ptr_num in some kind of bind or lambda to do the dereference without creating a separate function to do so.
The second part, the cast, would be something like:
int main() {
std::vector<double*> nums(10);
std::generate(nums.begin(), nums.end(), get_ptr_num) // cannot convert from int** to double*
}
This seems like it would be trivial to do with C++ 11 lambdas, but I can't use C++ 11.
The last part about this being a member function would be something more like this:
class IntGenerator {
public:
int** get_ptr_num() { int* i = new int(5); return new int*(i); }
}
int main() {
IntGenerator int_gen;
std::vector<int*> nums(10);
std::generate(nums.begin(), nums.end(), boost::bind(&IntGenerator::get_ptr_num, int_gen)) // cannot convert from int** to int*
}