I am trying to do this: maitain two vectors of strings whereby one vector stores values and the second stores references of the same values. I thought using boost::reference_wrapper
would do the trick but it seems it won't. My platform is Visual C++ 2008.
std::vector<std::string> str_vec;
str_vec.push_back("abc");
str_vec.push_back("cde");
str_vec.push_back("fgh");
std::vector<boost::reference_wrapper<std::string> > str_view;
for(std::vector<std::string>::iterator it = str_vec.begin(); it != str_vec.end(); ++it)
{
str_view.push_back(*it);
}
This is the error:
error C2664: 'std::vector<_Ty>::push_back' : cannot convert parameter 1 from std::basic_string<_Elem,_Traits,_Ax>' to 'const boost::reference
I could use boost::shared_ptr
but I thought a reference better expresses my intent. This code can probably work in C++11 using std::reference_wrapper
but that is not available to me right now.