I'm used to have a vector
of wstring
. I need to store the line number for each string, so I refactored the vector to be vector<pair<wstring, size_t>>
. If possible, I'd still like to use this vector like a vector<wstring>
in some contexts. This is my code:
typedef std::pair<std::wstring, size_t> LineNoPair;
typedef std::vector<LineNoPair> LineNos;
LineNos lines;
// Split lines, but don't split at line continuations
boost::split_regex(lines, // <-- I'd like to use `lines` as the split target
contents,
boost::wregex(L"(((?<![_])\\r\\n)|((?<![_\\r])\\n))"));
for (LineNoPair& line : lines)
{
// remove line continuations from string
boost::replace_all_regex(line.first,
boost::wregex(L"(_?[ ]*\\r?\\n)"),
std::wstring());
}
I could simply use a vector of strings and a separate vector of line numbers, but I'd like to be able to iterate over these items together.
So, the general question is: Is there a thing which lets me use a vector
of tuples like a vector of one of the tuple's types?
This question is different from this one as I need a vector-compatible interface (including swap
) whereas the other question is only about iterator adaptors.