In C++11 how do I create a map of queues?

How do I create a map of queues and dynamically add queues to it?  Suppose I have
map<string,queue<string>> myQueues;

Open in new window

 I am doing this from a method in a class so while the following is legal, it doesn't do the job
queue<string> q1;
myQueues["foo"] = q1;

Open in new window

What I really want to do is something like this (not legal tho)
myQueues["bar"] = new queue<string>;

Open in new window

What's the legal way to do this?

Just to be clear this is a simplified and contrived example to make the question simple. In the real code, I have a producer thread managed by a class.  The map is an instance variable of the class. The class needs to sometimes dynamically create a new consumer thread and a queue to communicate with it.  The real queues need to be thread-safe queues and the map variable is actually some kind of a handle, but to keep this question simple I'm posing it with standard classes.
anAppBuilderAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZoppoCommented:
Hi anAppBuilder,

what do you mean with it doesn't do the job?

Here I wrote a little test and IMO it works as expected:
	using namespace std;

	map<string,queue<string>> myQueues;

	queue<string> q;

	q.push( "Hello" );
	q.push( "World" );

	myQueues["foo"] = q;

	myQueues["bar"].push( "Another" );
	myQueues["bar"].push( "queue" );

	for ( auto i = myQueues.begin(); i != myQueues.end(); i++ )
	{
		cout << "Key: " << i->first << endl << "Values: ";

		while ( false == i->second.empty() )
		{
			cout << (i->second.front()) << ", ";
			i->second.pop();
		}

		cout << endl;
	}

Open in new window

The output is:
Key: bar
Values: Another, queue,
Key: foo
Values: Hello, World,

Open in new window

Please could you describe more detailed what problems you have with it?

ZOPPO
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
anAppBuilderAuthor Commented:
Thank you, Zoppo.   It does work.  I must have had some other problem
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.