[assign] initializing nested data structures

Hi, I'm trying to use Boost.Assign to test an output formatting facility, but I'm having trouble translating pseudocode with brace-initializers into working C++. E.g., how to you translate this: vector< list< pair<string, string> > > v = { { make_pair("hello", "goodbye"), make_pair("morning", "evening"), make_pair("cold", "hot") }, { make_pair("hello", "goodbye"), make_pair("morning", "evening"), make_pair("cold", "hot") } }; The following works on VC7.1, but not on como or gcc 3.4.1: vector< list< pair<string, string> > > v = list_of( list_of( make_pair("hello", "goodbye") ) ( make_pair("morning", "evening") ) ( make_pair("cold", "hot") ) ) ( list_of( make_pair("hello", "goodbye") ) ( make_pair("morning", "evening") ) ( make_pair("cold", "hot") ) ); What am I doing wrong? Best Regards, Jonathan

| Hi, | I'm trying to use Boost.Assign to test an output formatting facility, but | I'm having trouble translating pseudocode with brace-initializers into working | C++. E.g., how to you translate this: | | vector< list< pair<string, string> > > v = | { { make_pair("hello", "goodbye"), | make_pair("morning", "evening"), | make_pair("cold", "hot") }, | { make_pair("hello", "goodbye"), | make_pair("morning", "evening"), | make_pair("cold", "hot") } }; | | The following works on VC7.1, but not on como or gcc 3.4.1: | | vector< list< pair<string, string> > > v = | list_of( | list_of( make_pair("hello", "goodbye") ) | ( make_pair("morning", "evening") ) | ( make_pair("cold", "hot") ) | ) | ( | list_of( make_pair("hello", "goodbye") ) | ( make_pair("morning", "evening") ) | ( make_pair("cold", "hot") ) | ); | | What am I doing wrong? nothing AFAICT. If I use como + dinkumware, then it works on that compiler too, so It might be a std-library issue. You could try to help the compiler a little: #include <boost/assign.hpp> #include <vector> #include <list> #include <string> int main() { using namespace std; using namespace boost::assign; typedef pair<string,string> pair_t; typedef list< pair_t > list_t; vector< list_t > v = list_of< list_t >( list_of<pair_t>( "hello", "goodbye" ) ( "morning", "evening" ) ( "cold", "hot" ) ) ( list_of<pair_t>( "hello", "goodbye" ) ( "morning", "evening" ) ( "cold", "hot" ) ); } -Thorsten PS: do you mind if I steal your example for the article I'm writing?

"Thorsten Ottosen" <nesotto@cs.auc.dk> wrote in message news:00ba01c4bbd5$a9d5dd50$0b40a8c0@nesottolap...
| What am I doing wrong?
nothing AFAICT. If I use como + dinkumware, then it works on that compiler too, so It might be a std-library issue.
You could try to help the compiler a little:
#include <boost/assign.hpp> #include <vector> #include <list> #include <string>
int main() { using namespace std; using namespace boost::assign;
typedef pair<string,string> pair_t; typedef list< pair_t > list_t;
vector< list_t > v = list_of< list_t >( list_of<pair_t>( "hello", "goodbye" ) ( "morning", "evening" ) ( "cold", "hot" ) ) ( list_of<pair_t>( "hello", "goodbye" ) ( "morning", "evening" ) ( "cold", "hot" ) ); }
Thanks.
-Thorsten
PS: do you mind if I steal your example for the article I'm writing?
Steal away! Jonathan
participants (2)
-
Jonathan Turkanis
-
Thorsten Ottosen