Raindog | 1 Dec 01:10
Gravatar

Simple suggestion for BOOST_FUSION_ADAPT_STRUCT

Perhaps for structures whose main purpose is to be used w/ fusion, a 
macro can be used that will both define the structure and adapt it so that:

    struct foo
    {
         int var1;
         int var2;
         std::string name;
         std::string name2;
    };

    BOOST_FUSION_ADAPT_STRUCT(
         foo,
         (int, var1)
         (int, var2)
         (std::string, name)
         (std::string, name2)
    )

Can be shorted to something like:

    BOOST_FUSION_DEFINE_AND_ADAPT_STRUCT(
         foo,
         (int, var1)
         (int, var2)
         (std::string, name)
         (std::string, name2)
    )

-------------------------------------------------------------------------
(Continue reading)

Joel de Guzman | 1 Dec 01:33
Picon
Favicon

Re: Simple suggestion for BOOST_FUSION_ADAPT_STRUCT

Raindog wrote:
> Perhaps for structures whose main purpose is to be used w/ fusion, a 
> macro can be used that will both define the structure and adapt it so that:
> 
>     struct foo
>     {
>          int var1;
>          int var2;
>          std::string name;
>          std::string name2;
>     };
> 
>     BOOST_FUSION_ADAPT_STRUCT(
>          foo,
>          (int, var1)
>          (int, var2)
>          (std::string, name)
>          (std::string, name2)
>     )
> 
> Can be shorted to something like:
> 
>     BOOST_FUSION_DEFINE_AND_ADAPT_STRUCT(
>          foo,
>          (int, var1)
>          (int, var2)
>          (std::string, name)
>          (std::string, name2)
>     )

(Continue reading)

Matthias Vallentin | 1 Dec 03:02
Picon
Favicon
Gravatar

[karma] streaming empty containers

Hi there,

how do I reliably stream containers regardless of their size? The
following example only works with non-empty containers:

    std::vector<int> v;

    std::cout << boost::spirit::karma::format(
                    '{' << (stream % ", ") << '}',
                    v
                ) << std::endl;

If the container is empty the output is

    {%

and does not include a closing bracket. In fact, the entire stream is
cut off at the point of the first '{'. Of course, I could manually check
if the container is empty but it would be sweet if karma can handle
empty containers as well (output: "{}"). Could it be that I am misusing
karma here?

   Matthias
--

-- 
Matthias Vallentin
vallentin <at> icsi.berkeley.edu
http://matthias.vallentin.cc

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
(Continue reading)

Matthias Vallentin | 1 Dec 03:21
Picon
Favicon

Re: [karma] streaming a std::map

On Sun, Nov 30, 2008 at 04:10:53PM -0600, Hartmut Kaiser wrote:
> But, since std::pair is a fusion sequence (at least if you include the
> proper fusion header for that), you could write for instance:
> 
>     out << karma::format(
>                         '{' << ((int_ << lit) % ", ") << '}',
>                         container
>                         );
> 
> if the type of the map is map<int, string>.

Yeah, works like a charm, thanks! The appropriate header is by the way:

    <boost/fusion/include/std_pair.hpp>

   Matthias
--

-- 
Matthias Vallentin
vallentin <at> icsi.berkeley.edu
http://matthias.vallentin.cc

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
Hartmut Kaiser | 1 Dec 05:05
Picon
Gravatar

Re: [karma] streaming empty containers

> how do I reliably stream containers regardless of their size? The
> following example only works with non-empty containers:
> 
>     std::vector<int> v;
> 
>     std::cout << boost::spirit::karma::format(
>                     '{' << (stream % ", ") << '}',
>                     v
>                 ) << std::endl;
> 
> If the container is empty the output is
> 
>     {%
> 
> and does not include a closing bracket. In fact, the entire stream is
> cut off at the point of the first '{'. Of course, I could manually
> check
> if the container is empty but it would be sweet if karma can handle
> empty containers as well (output: "{}"). Could it be that I am misusing
> karma here?

The list generator a << ',' is equivalent to a << *(',' << a), so if you
need support for empty containers just make it optional: -(a << ',').

The generated output is cut off because the generator failed and it's not
possible to unroll output which already has been generated. But the stream
should have gotten its ios_base::badbit flag set (or for that matter, if you
enable exceptions on the stream, it should have thrown).

Regards Hartmut
(Continue reading)

Matthias Vallentin | 1 Dec 06:47
Picon
Favicon

Re: [karma] streaming empty containers

On Sun, Nov 30, 2008 at 10:05:27PM -0600, Hartmut Kaiser wrote:
> The list generator a << ',' is equivalent to a << *(',' << a), so if you
> need support for empty containers just make it optional: -(a << ',').

Finally I see the connection to Spirit.Qi. Thanks for these examples.

   Matthias
--

-- 
Matthias Vallentin
vallentin <at> icsi.berkeley.edu
http://matthias.vallentin.cc

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
Joel de Guzman | 1 Dec 07:02
Picon
Favicon

Re: [karma] streaming empty containers

Hartmut Kaiser wrote:
> 
> The list generator a << ',' is equivalent to a << *(',' << a), so if you
> need support for empty containers just make it optional: -(a << ',').

Just to clarify, I think Hartmut meant:

     -(a % ',')

Cheers!
--

-- 
Joel de Guzman
http://www.boostpro.com
http://spirit.sf.net

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
Matthias Vallentin | 1 Dec 08:12
Picon
Favicon
Gravatar

Re: [karma] streaming empty containers

On Mon, Dec 01, 2008 at 02:02:34PM +0800, Joel de Guzman wrote:
> > The list generator a << ',' is equivalent to a << *(',' << a), so if you
> > need support for empty containers just make it optional: -(a << ',').
> 
> Just to clarify, I think Hartmut meant:
> 
>      -(a % ',')

Yeah, haven't even noticed it. There is one other issue I ran into when
applying the optional operator. Simply prepending the '-' results in the
following compile error:

[...]/boost-1_37/boost/spirit/home/karma/operator/list.hpp:62: error: call of overloaded
‘generate(const boost::spirit::component<boost::spirit::karma::domain,
boost::spirit::karma::any_stream<char>, boost::fusion::nil>&,
boost::spirit::karma::detail::output_iterator<boost::spirit::karma::detail::ostream_iterator<char,
char, std::char_traits<char> >, void>&, const boost::fusion::unused_type&, const
boost::fusion::unused_type&, boost::spirit::unused_type)’ is ambiguous

using the following construct:

    std::cout << boost::spirit::karma::format(
                    '{' << -(stream % ", ") << '}',
                    v
                ) << std::endl;

Any ideas?

   Matthias
--

-- 
(Continue reading)

Hartmut Kaiser | 1 Dec 14:31
Picon
Gravatar

Re: [karma] streaming empty containers

> Hartmut Kaiser wrote:
> >
> > The list generator a << ',' is equivalent to a << *(',' << a), so if
> you
> > need support for empty containers just make it optional: -(a << ',').
> 
> Just to clarify, I think Hartmut meant:
> 
>      -(a % ',')

Yeah, sorry. Was too tired yesterday...

Regards Hartmut

> 
> Cheers!
> --
> Joel de Guzman
> http://www.boostpro.com
> http://spirit.sf.net
> 
> 
> -----------------------------------------------------------------------
> --
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the
> world
(Continue reading)

Hartmut Kaiser | 1 Dec 14:34
Picon
Gravatar

Re: [karma] streaming empty containers

> On Mon, Dec 01, 2008 at 02:02:34PM +0800, Joel de Guzman wrote:
> > > The list generator a << ',' is equivalent to a << *(',' << a), so
> if you
> > > need support for empty containers just make it optional: -(a <<
> ',').
> >
> > Just to clarify, I think Hartmut meant:
> >
> >      -(a % ',')
> 
> Yeah, haven't even noticed it. There is one other issue I ran into when
> applying the optional operator. Simply prepending the '-' results in
> the
> following compile error:
> 
> [...]/boost-1_37/boost/spirit/home/karma/operator/list.hpp:62: error:
> call of overloaded ‘generate(const
> boost::spirit::component<boost::spirit::karma::domain,
> boost::spirit::karma::any_stream<char>, boost::fusion::nil>&,
> boost::spirit::karma::detail::output_iterator<boost::spirit::karma::det
> ail::ostream_iterator<char, char, std::char_traits<char> >, void>&,
> const boost::fusion::unused_type&, const boost::fusion::unused_type&,
> boost::spirit::unused_type)’ is ambiguous
> 
> using the following construct:
> 
>     std::cout << boost::spirit::karma::format(
>                     '{' << -(stream % ", ") << '}',
>                     v
>                 ) << std::endl;
(Continue reading)


Gmane