Boost logo

Boost :

From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2004-10-26 22:33:02


| 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?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk