std::vector
, std::list
and std::deque
have std::back_inserter
, and std::set
has std::inserter
.
For std::stack
and std::priority_queue
I would assume the equivalent inserter would be a push()
but I can't seem to find the correct function to call.
My intent is to be able to use the following function with the correct insert iterator:
#include <string>
#include <queue>
#include <iterator>
template<typename outiter>
void foo(outiter oitr)
{
static const std::string s1 ("abcdefghji");
static const std::string s2 ("1234567890");
*oitr++ = s1;
*oitr++ = s2;
}
int main()
{
std::priority_queue<std::string> spq;
std::stack<std::string> stk;
foo(std::inserter(spq));
foo(std::inserter(stk));
return 0;
}
See Question&Answers more detail:os