Seth Heeren | 1 Feb 01:04
Picon
Favicon

Re: Nested structs and Karma

On 02/01/2012 12:57 AM, Seth Heeren wrote:
> you'll end up calling a parser fule
sic. that should have read "generator rule"

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
Öyvind Strand | 1 Feb 21:39
Picon

Re: Nested structs and Karma




>Well, again, it _might_ be an issue. I don't see why it should work like this, but the first line reported by gcc is preceded by

>        // This handles the case where the attribute is a single element fusion
>        // sequence. We silently extract the only element and treat it as the
>        // attribute to generate output from.

>which pretty much tells the whole story: The structs are adapted to a fusion sequence of a single element. When extracted in a generator, it decays to the single element. If this happens early/too often, you'll end up calling a parser fule that expects Inner/Outer with an int as the attribute reference.

Thanks for pointing out that the single element sequence is a special case. When I have more than one member in the structs things work as expected.

Regards

Öyvind

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Spirit-general mailing list
Spirit-general <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spirit-general
Öyvind Strand | 1 Feb 21:40
Picon

Problem refering to data member of nested struct in Karma

Hi,

If I have nested data types like these (I've added the dummy member to avoid the special case where
the attribute is a single element fusion sequence which can lead to unrelated problems when compiling):

struct Inner {
  int value;
  double dummy;
};
struct Outer {
  Inner inner;
  double dummy;
};

and want to refer to the member value of the deeper struct I would do it like this using stand-alone phoenix:

Outer data;
using phx::arg_names::arg1;
(
  ((&arg1)->*&Outer::inner)->*&Inner::value
)
(data);

Doing the same thing in qi works fine:

typedef std::string::iterator IIter;
qi::rule<IIter, Inner()> inner_input_rule = qi::int_ >> qi::double_;
qi::rule<IIter, Outer()> outer_input_rule;
  
outer_input_rule = (inner_input_rule >> qi::double_)[
  ((&qi::_val)->*&Outer::inner)->*&Inner::value
];

But it won't compile when using karma:

typedef std::ostream_iterator<char> OIter;
kma::rule<OIter, Inner()> inner_output_rule = kma::int_ << kma::double_;
kma::rule<OIter, Outer()> outer_output_rule;
  
using phx::local_names::_a;
outer_output_rule = (inner_output_rule << kma::double_)[
  //This phoenix expression won't compile
  //((&kma::_val)->*&Outer::inner)->*&Inner::value,
    
  //Split it and it will compile
  phx::let(_a = (&kma::_val)->*&Outer::inner)[
    (&_a)->*&Inner::value
  ]
];

There are of course several ways to work around this like using at_c<>(at_c<>()) or using local variables so it's not
really a big problem but it would make programs more readable if you were able to do it the same way as in qi.

Regards

Öyvind



Attachment (main.cpp): text/x-c++src, 1563 bytes
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Spirit-general mailing list
Spirit-general <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spirit-general
Öyvind Strand | 5 Feb 18:50
Picon

Phoenix pointer to member operator not working when compiling with gcc and -std=c++0x

Hi,

A phoenix expression using the pointer to member operator pointing to a member function doesn't compile. This occurs only
when compiling with -std=c++0x AND taking the address of the object inside the phoenix expression. There's no problem
when pointing to a data member or passing something that is already a pointer to the phoenix expression or compiling without -std=c++0x.

class type {
 public:
  void func() {}
  int data;
};

int main() {
  using boost::phoenix::arg_names::arg1;
  
  type obj;
  
  (
    ((&arg1)->*&type::func)() , //Doesn't compile
    (&arg1)->*&type::data       //Compiles
  )
  (obj);
  
  (
    (arg1->*&type::func)() , //Compiles
    arg1->*&type::data       //Compiles
  )
  (&obj);
  
  return 0;
}

Regards

Öyvind


Attachment (main.cpp): text/x-c++src, 385 bytes
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Spirit-general mailing list
Spirit-general <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spirit-general
Claude | 5 Feb 22:45
Picon
Favicon

Rule and C++11 auto type on VS2010

Hi!
I used this code for parsing a date in format yyyy-mm-dd:

    uint32_t day=0,month=0;
    uint32_t year;
    std::string myStr("1974-5-10");

    std::string::const_iterator begin = myStr.begin(), end = myStr.end();

    auto rDate = qi::uint_>>'-'>>qi::uint_>>'-'>>qi::uint_;

    if (qi::phrase_parse(begin, end, rDate, qi::space,year,month,day) )
	{
         cout<<"Parse Ok!"<<endl;
	 cout&lt;&lt;&quot;Year: &quot;&lt;&lt;year&lt;&lt;&quot; Month:
&quot;&lt;&lt;month&lt;&lt;&quot; Day: &quot;&lt;&lt;day&lt;&lt;endl;
	}

This code work well, but if I use it in most complex program, it don’t work
&lt;smiley image=&quot;smiley_what.gif&quot;/>

I discovered that the problem is the rDate variable. If it is a C++11 /auto/
variable, in my complex program, on the Visual C++2010, phrase_parse() don’t
parse correctly. (this problem are not present on GCC 4.6.1 on Ubuntu!)

For this reason I changed the rValue type:

qi::rule<std::string::const_iterator> rDate =
qi::uint_>>'-'>>qi::uint_>>'-'>>qi::uint_;
	
Now phrase_parse() work, but I don’t obtain the correct value of year,month
an day.

I think the problem is the type of rdate.
How can I fix?

Why in Visual C++ auto type don't work correctly?

--
View this message in context: http://boost.2283326.n4.nabble.com/Rule-and-C-11-auto-type-on-VS2010-tp4359859p4359859.html
Sent from the spirit-general mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Spirit-general mailing list
Spirit-general <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spirit-general
Michael Caisse | 5 Feb 23:14

Re: Rule and C++11 auto type on VS2010

Hi Claude -

On 2/5/2012 1:45 PM, Claude wrote:
> Hi!
> I used this code for parsing a date in format yyyy-mm-dd:
>

<snip code>

>
>      auto rDate = qi::uint_>>'-'>>qi::uint_>>'-'>>qi::uint_;
>

>
> I discovered that the problem is the rDate variable. If it is a C++11 /auto/
> variable, in my complex program, on the Visual C++2010, phrase_parse() don’t
> parse correctly. (this problem are not present on GCC 4.6.1 on Ubuntu!)
>
> For this reason I changed the rValue type:
>
> qi::rule<std::string::const_iterator>  rDate =
> qi::uint_>>'-'>>qi::uint_>>'-'>>qi::uint_;
> 	
> Now phrase_parse() work, but I don’t obtain the correct value of year,month
> an day.
>
> I think the problem is the type of rdate.
> How can I fix?
>
> Why in Visual C++ auto type don't work correctly?
>

This is a known issue with auto in MSVC and spirit rules. In particular 
I believe the issues has to do with needing a deep copy of the proto 
grammar which isn't happening.

Please see this article for more details:
<http://boost-spirit.com/home/articles/qi-example/zero-to-60-mph-in-2-seconds/>

In particular ... please see the comments and the caution to use 
BOOST_SPIRIT_AUTO.

HTH -
michael

--

-- 

----------------------------------
Michael Caisse
Object Modeling Designs
www.objectmodelingdesigns.com

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Spirit-general mailing list
Spirit-general <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spirit-general
Seth Heeren | 6 Feb 03:30
Picon
Favicon

Re: Phoenix pointer to member operator not working when compiling with gcc and -std=c++0x

On 02/05/2012 06:50 PM, Öyvind Strand wrote:
Hi,

A phoenix expression using the pointer to member operator pointing to a member function doesn't compile. This occurs only
when compiling with -std=c++0x AND taking the address of the object inside the phoenix expression. There's no problem
when pointing to a data member or passing something that is already a pointer to the phoenix expression or compiling without -std=c++0x.

That looks like an awesome selfcontained test. I'm not exactly sure I get the inent  of the comma-operators ('lazy' statement separation?) and
    ((&arg1)->*&type::func)() , //Doesn't compile
apparently redundant function call application here: ((&arg1)->*&type::func)(); I'm assuming that means 'partial function application' (in this case, applying none of 1 existing parameters).

Regardless, the following compiles for me on boost 1_48 with gcc 4.6.1 with or without -std=c++0x:
    ((&arg1)->*(&type::func))  ( obj);   //Compiles
    ((&arg1)->*(&type::func))()( obj);   //Compiles - breaks with -std=c++0x
    ((&arg1)->*(&type::data))  ( obj);   //Compiles

    ((&arg1)->*(&type::func))  (&obj);   //Compiles
    (( arg1)->*(&type::func))()(&obj);   //Compiles - breaks with phoenixV2
    (( arg1)->*(&type::data))  (&obj);   //Compiles - breaks with phoenixV2

    // compound phoenix bodies
    (((&arg1)->*(&type::func)),          //Compiles
     ((&arg1)->*(&type::func))(),        //Compiles - breaks with -std=c++0x
     ((&arg1)->*(&type::data)))( obj);   //Compiles
                                                                            
    (((&arg1)->*(&type::func)),          //Compiles
     (( arg1)->*(&type::func))(),        //Compiles - breaks with phoenixV2
     (( arg1)->*(&type::data)))(&obj);   //Compiles - breaks with phoenixV2

See also attached test.cpp

Is there any more information that can be gleaned from this?
Attachment (test.cpp): text/x-c++src, 1192 bytes
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Spirit-general mailing list
Spirit-general <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spirit-general
Thomas Heller | 6 Feb 12:53

Re: Phoenix pointer to member operator not working when compiling with gcc and -std=c++0x

On Mon, Feb 6, 2012 at 3:30 AM, Seth Heeren <bugs <at> sehe.nl> wrote:
> On 02/05/2012 06:50 PM, Öyvind Strand wrote:
>
> Hi,
>
> A phoenix expression using the pointer to member operator pointing to a
> member function doesn't compile. This occurs only
> when compiling with -std=c++0x AND taking the address of the object inside
> the phoenix expression. There's no problem
> when pointing to a data member or passing something that is already a
> pointer to the phoenix expression or compiling without -std=c++0x.
>
>
> That looks like an awesome selfcontained test. I'm not exactly sure I get
> the inent  of the comma-operators ('lazy' statement separation?) and
>
>     ((&arg1)->*&type::func)() , //Doesn't compile
>
> apparently redundant function call application here:
> ((&arg1)->*&type::func)(); I'm assuming that means 'partial function
> application' (in this case, applying none of 1 existing parameters).
>
> Regardless, the following compiles for me on boost 1_48 with gcc 4.6.1 with
> or without -std=c++0x:
>
>     ((&arg1)->*(&type::func))  ( obj);   //Compiles
>     ((&arg1)->*(&type::func))()( obj);   //Compiles - breaks with -std=c++0x
>     ((&arg1)->*(&type::data))  ( obj);   //Compiles
>
>     ((&arg1)->*(&type::func))  (&obj);   //Compiles
>     (( arg1)->*(&type::func))()(&obj);   //Compiles - breaks with phoenixV2
>     (( arg1)->*(&type::data))  (&obj);   //Compiles - breaks with phoenixV2
>
>     // compound phoenix bodies
>     (((&arg1)->*(&type::func)),          //Compiles
>      ((&arg1)->*(&type::func))(),        //Compiles - breaks with -std=c++0x
>      ((&arg1)->*(&type::data)))( obj);   //Compiles
>
>     (((&arg1)->*(&type::func)),          //Compiles
>      (( arg1)->*(&type::func))(),        //Compiles - breaks with phoenixV2
>      (( arg1)->*(&type::data)))(&obj);   //Compiles - breaks with phoenixV2
>
> See also attached test.cpp
>
> Is there any more information that can be gleaned from this?

Let me try to explain (only speaking for Phoenix V3):
  1) Phoenix V3 is currently broken when using with decltype as the result_of
      implementation: https://svn.boost.org/trac/boost/ticket/5687
      Note: BOOST_RESULT_OF_USE_DECLTYPE isn't turned on by default
      in C++ 11 mode.
  2) ((&arg1)->*(&type::func)) returns something which is not a phoenix actor.
      It returns a callable which is, when called turned into the proper member
      function pointer phoenix actor. This should probably be checked in the
      phoenix grammar. (Side note: it doesn't make any sense to take the
      pointer again, in the case where the 1st argument is already a pointer).
      This is of course different if we want a pointer to a member
variable, which
      doesn't need the function application.
  3) I can confirm that ((&arg1)->*(&type::func))()( obj); doesn't
compile ... this is
      a bug! (The wrong operator->* is selected, needs investigation)
  4) As a workaround, I can offer this:
    bind(&type::func, &arg1)(obj);
    bind(&type::func, arg1)(obj);
    bind(&type::func, arg1)(&obj);

Regards,
Thomas

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Spirit-general mailing list
Spirit-general <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spirit-general
Öyvind Strand | 6 Feb 18:38
Picon

Re: Phoenix pointer to member operator not working when compiling with gcc and -std=c++0x

From: bugs <at> sehe.nl
I'm not exactly sure I get the inent  of the comma-operators ('lazy' statement separation?) 

Yes, that's the function comma has as I understand it.

and apparently redundant function call application here: ((&arg1)->*&type::func)(); I'm assuming that means 'partial function application' (in this case, applying none of 1 existing parameters).

It's the syntax used to separate member function (arg1->*&type::func)() from member data (arg1->*&type::data) (presuming arg1 is a pointer). I've never fully understood how it works but apparently
like this (quoting from Thomas's reply):

((&arg1)->*(&type::func)) returns something which is not a phoenix actor.
It returns a callable which is, when called turned into the proper member
function pointer phoenix actor.

Regardless, the following compiles for me on boost 1_48 with gcc 4.6.1 with or without -std=c++0x:
[snip]

Thanks for providing more cases.

Regards

Öyvind
   
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Spirit-general mailing list
Spirit-general <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spirit-general
Öyvind Strand | 6 Feb 18:55
Picon

Re: Phoenix pointer to member operator not working when compiling with gcc and -std=c++0x



> Date: Mon, 6 Feb 2012 12:53:31 +0100
> From: thom.heller <at> googlemail.com

> 2) ((&arg1)->*(&type::func)) returns something which is not a phoenix actor.
> It returns a callable which is, when called turned into the proper member
> function pointer phoenix actor. This should probably be checked in the
> phoenix grammar. (Side note: it doesn't make any sense to take the
> pointer again, in the case where the 1st argument is already a pointer).
> This is of course different if we want a pointer to a member
> variable, which
> doesn't need the function application.

Ok thanks I never quite understood how that worked.

> 3) I can confirm that ((&arg1)->*(&type::func))()( obj); doesn't
> compile ... this is
> a bug! (The wrong operator->* is selected, needs investigation)
> 4) As a workaround, I can offer this:
> bind(&type::func, &arg1)(obj);
> bind(&type::func, arg1)(obj);
> bind(&type::func, arg1)(&obj);

Great thanks. My first workaround was to do

let(_a = &arg1) [(_a->*&type::func)()]

which strangely enough works (the problem has to do with deducing the type of arg1?) but the bind solution is more readable.

Regards

Öyvind
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Spirit-general mailing list
Spirit-general <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spirit-general

Gmane