Boost fusion nested sequence with spirit does not work

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Boost fusion nested sequence with spirit does not work

lucidbee
I am trying to create a boost fusion nested sequence. It would correspond to a
std::vector<std::pair<T1, T2>>.

When my nested sequence is
std::vector<std::vector<T1>> it compiles and works correctly.

But I need a vector of pairs of T1, T2 type.
That gets compiler errors.

Here is the working macro invocation:

BOOST_FUSION_ADAPT_TPL_STRUCT(
    (StringType),
    (MySchemaDeclaration) (StringType),
    (StringType, name)
    (std::vector<std::vector<StringType>>, fields)     // this works
    )

(It is used in the following rule:
qi::rule<typename MyIterator, typename MySchemaDeclaration(), typename
MySkipper>  schema_rule;)

This std::pair version gets a compiler error:
BOOST_FUSION_ADAPT_TPL_STRUCT(
    (StringType),
    (MySchemaDeclaration) (StringType),
    (StringType, name)
    (std::vector<std::pair<StringType, T2>>, fields)
    )

I used it with the suggested includes:
#include <boost/fusion/adapted/std_pair.hpp>
#include <boost/fusion/include/std_pair.hpp>

The error is:
2>c:\brain\brain\brain\src\inkling\ast.hpp(135): warning C4002:
    too many actual parameters for macro 'BOOST_FUSION_ADAPT_STRUCT_FILLER_1'
2>c:\brain\brain\brain\src\inkling\ast.hpp(135): error C2146:
    syntax error : missing ',' before identifier 'attribute_type'
2>c:\brain\brain\brain\src\inkling\ast.hpp(135): error C2065:
    'attribute_type' : undeclared identifier
2>c:\brain\brain\brain\src\inkling\ast.hpp(135): error C2143:
    syntax error : missing '>' before ';'
2>c:\brain\brain\brain\src\inkling\ast.hpp(135): error C2923:
    'std::pair' : 'attribute_type' is not a valid template type
     argument for parameter '_Ty2'

This is the VS13 compiler.
Reply | Threaded
Open this post in threaded view
|

Re: Boost fusion nested sequence with spirit does not work

Kohei Takahashi
Hi lucidbee,

On 2015/10/01 7:54, lucidbee wrote:
> This std::pair version gets a compiler error:
> BOOST_FUSION_ADAPT_TPL_STRUCT(
>     (StringType),
>     (MySchemaDeclaration) (StringType),
>     (StringType, name)
>     (std::vector<std::pair&lt;StringType, T2>>, fields)
>     )
This is language limitation.
Since preprocessor isn't aware template, preprocessor will tokenize
template arguments into two (or more) tokens, i.e.
'(vector<pair<StringType, T2>>, fields)' will become
'vector<pair<StringType', 'T2>>' and 'fields', not
'vector<pair<StringType, T2>>' and 'fields'.

To avoid this issue, just typedef such type or use
Boost.Utility/IdentityType
(http://www.boost.org/libs/utility/identity_type/doc/html/index.html).

Regards,
Kohei Takahashi



------------------------------------------------------------------------------

_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general

signature.asc (836 bytes) Download Attachment