Boost logo

Boost Users :

Subject: Re: [Boost-users] [Proto] Default-constructing a proto::terminal
From: Eric Niebler (eric_at_[hidden])
Date: 2010-09-16 09:55:28


On 9/16/2010 9:09 AM, Roland Bock wrote:
> Hi,
>
> I have a class which has boost::proto::terminal members like this:
>
> struct _table
> {
> struct id
> {
> id(); // default constructible
> /*...*/
> };
> boost::proto::terminal<id> id_terminal;

Should be:

        boost::proto::terminal<id>::type id_terminal;

> };
>
> _table table;
>
> Will table.id_terminal be constructed correctly?

Yes.

> I am asking because in Proto's documentation terminals are always
> instantiated with curly braces, e.g.:
>
> typedef proto::terminal<int>::type int_;
> int_ i = {42}, j = {24};

Correct. If the value type of the terminal is POD, then the terminal can
be statically initialized (curly-braced initialization syntax). That's
important for terminals like, e.g., bind placeholders that live at
namespace scope. It looks like you're going to try to declare a table at
namespace scope, so this is something you'll need to think about. Try to
make the table::id struct POD. Then you can initialize table at
namespace scope like this:

  _table const table = {{{}}};

That way, you get static initialization and avoid any
order-of-initialization bugs.

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net