|
Boost Users : |
Subject: Re: [Boost-users] [fusion] making an inner struct boost fusion compatible?
From: Oswin Krause (Oswin.Krause_at_[hidden])
Date: 2012-09-21 05:16:32
Hi,
Again thanks a lot! I allready got my first small success after
scanning the file. I figured that what i needed was
BOOST_FUSION_DEFINE_STRUCT_INLINE_MEMBERS
Now i can write:
struct MyType{
struct type : boost::fusion::sequence_facade<
type,
boost::fusion::random_access_traversal_tag
> {
#define attributes (vector<T>,a)(vector<U>,b)(vector<V>,c)
BOOST_FUSION_DEFINE_STRUCT_INLINE_MEMBERS(type, attributes)
//add own methods here...
//however, does this work?
struct reference{
#define refAttributes (T&,a)(U&,b)(V&,c)
BOOST_FUSION_DEFINE_STRUCT_INLINE_MEMBERS(reference,
refAttributes)
};
};
};
I am not sure whether i can put reference types into the structure.
because in the macro there is a ctor created as:
#define BOOST_FUSION_MAKE_COPY_CONSTRUCTOR(NAME, ATTRIBUTES_SEQ)
\
NAME(BOOST_PP_SEQ_FOR_EACH_I(
\
BOOST_FUSION_MAKE_CONST_REF_PARAM,
\
~,
\
ATTRIBUTES_SEQ))
\
...
\
#define BOOST_FUSION_MAKE_CONST_REF_PARAM(R, DATA, N, ATTRIBUTE)
\
BOOST_PP_COMMA_IF(N)
\
BOOST_PP_TUPLE_ELEM(2, 0, ATTRIBUTE) const&
\
BOOST_PP_TUPLE_ELEM(2, 1, ATTRIBUTE)
so there is an assumption that ATTRIBUTE is not a reference type.
Is there a reason why it is implemented that way? If not, i would like
to change the argument type to something like(not compiled):
(with ELEM = BOOST_PP_TUPLE_ELEM(2, 0, ATTRIBUTE))
typename mpl::if_<is_reference<ELEM>, ELEM, typename add_const<typename
remove_reference<ELEM>::type>::type& >::type
(if ELEM is a reference use ELEM as argument type, else try to get a
const reference in a safe way)
Anyways, Keep up the good work! Fusion is great :)
Gretings,
Oswin Krause
On 2012-09-21 09:52, Nathan Ridge wrote:
>> thanks for the reply.
>> Is it possible to just copy and rename the macro, or does it depend
>> on
>> newer features of fusion? I need to be compatible with boost 1.45 so
>> i
>> can't use it directly (also i need to add a few more functions to
>> the
>> structure later on)
>
> BOOST_FUSION_DEFINE_STRUCT_INLINE is implemented using the
> sequence_facade
> and iterator_facade extension mechanisms, which were present in Boost
> 1.45
> [1] [2]. So, it should be straightforward to back-port the macro to
> 1.45.
>
> Regards,
> Nate
>
> [1]
>
> http://www.boost.org/doc/libs/1_45_0/libs/fusion/doc/html/fusion/extension/sequence_facade.html
> [2]
>
> http://www.boost.org/doc/libs/1_45_0/libs/fusion/doc/html/fusion/extension/iterator_facade.html
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
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