[Proto] Default-constructing a proto::terminal

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;
};
_table table;
Will table.id_terminal be constructed correctly?
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};
template<int I>
struct placeholder
{};
proto::terminal

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

On 09/16/2010 03:55 PM, Eric Niebler wrote:
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.
OK, got it! Thanks for the explanation :-) Regards, Roland
participants (2)
-
Eric Niebler
-
Roland Bock