Boost logo

Boost Users :

Subject: Re: [Boost-users] fusion struct adapted, latest trunk changes
From: Hicham Mouline (hicham_at_[hidden])
Date: 2010-02-24 05:53:00


-----Original Message-----
From: "Hicham Mouline" [hicham_at_[hidden]]
Date: 24/02/2010 10:17 AM
To: boost-users_at_[hidden]
Subject: Re: fusion struct adapted, latest trunk changes

Christopher,
<snip>
1. temporarily, which files should I add this tweak to (boost\fusion\adapted\struct\extension.hpp is gone)
2. I understand your changes are about adapting class/struct templates. Where should I add this tweak to if I wish to use it for adapted templates,

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

Attached are the 2 files I have changed to trunk now. It works for my non template struct case, I haven't tested yet for struct templates /classes/ class templates

Regards,

ps: I hope to be able to add this later for the other headers.

attached: boost\fusion\adapted\struct\detail\adapt_base.hpp
attached: boost\fusion\adapted\struct\detail\extension.hpp

/*=============================================================================
    Copyright (c) 2009-2010 Christopher Schmidt

    Distributed under the Boost Software License, Version 1.0. (See accompanying
    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/

#ifndef BOOST_FUSION_ADAPTED_DETAIL_STRUCT_ADAPT_BASE_HPP
#define BOOST_FUSION_ADAPTED_DETAIL_STRUCT_ADAPT_BASE_HPP

#include <boost/config.hpp>
#include <boost/fusion/support/tag_of_fwd.hpp>

#include <boost/preprocessor/control/if.hpp>
#include <boost/preprocessor/seq/size.hpp>
#include <boost/preprocessor/seq/for_each.hpp>
#include <boost/preprocessor/seq/for_each_i.hpp>
#include <boost/preprocessor/seq/enum.hpp>
#include <boost/preprocessor/seq/seq.hpp>
#include <boost/preprocessor/tuple/eat.hpp>
#include <boost/preprocessor/tuple/elem.hpp>
#include <boost/mpl/tag.hpp>
#include <boost/type_traits/add_reference.hpp>
#include <boost/type_traits/add_const.hpp>

#define BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME_TEMPLATE_PARAMS(SEQ) \
    BOOST_PP_SEQ_HEAD(SEQ)<BOOST_PP_SEQ_ENUM(BOOST_PP_SEQ_TAIL(SEQ))>
#define BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(SEQ) \
    BOOST_PP_IF( \
        BOOST_PP_SEQ_HEAD(SEQ), \
        BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME_TEMPLATE_PARAMS, \
        BOOST_PP_SEQ_HEAD)(BOOST_PP_SEQ_TAIL(SEQ))

#define BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS_IMPL_C(R, _, ELEM) \
    (typename ELEM)
#define BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS_IMPL(SEQ) \
    BOOST_PP_SEQ_ENUM( \
        BOOST_PP_SEQ_FOR_EACH( \
            BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS_IMPL_C, \
            _, \
            BOOST_PP_SEQ_TAIL(SEQ)))
#define BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS(SEQ) \
    BOOST_PP_IF( \
        BOOST_PP_SEQ_HEAD(SEQ), \
        BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS_IMPL, \
        BOOST_PP_TUPLE_EAT(1))(SEQ)

#ifdef BOOST_NO_PARTIAL_SPECIALIZATION_IMPLICIT_DEFAULT_ARGS
# define BOOST_FUSION_ADAPT_STRUCT_TAG_OF_SPECIALIZATION( \
        MODIFIER, TEMPLATE_PARAMS_SEQ,NAME_SEQ,TAG) \
                                                                                \
    template< \
        BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS(TEMPLATE_PARAMS_SEQ) \
> \
    struct tag_of< \
        BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) MODIFIER \
      , void \
> \
    { \
        typedef TAG type; \
    };
#else
# define BOOST_FUSION_ADAPT_STRUCT_TAG_OF_SPECIALIZATION( \
        MODIFIER, TEMPLATE_PARAMS_SEQ,NAME_SEQ,TAG) \
                                                                                \
    template< \
        BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS(TEMPLATE_PARAMS_SEQ) \
> \
    struct tag_of<BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) MODIFIER> \
    { \
        typedef TAG type; \
    };
#endif

#define BOOST_FUSION_ADAPT_STRUCT_BASE_UNPACK_AND_CALL(R,DATA,I,ATTRIBUTE) \
    BOOST_PP_TUPLE_ELEM(3,0,DATA)( \
        BOOST_PP_TUPLE_ELEM(3,1,DATA), \
        BOOST_PP_TUPLE_ELEM(3,2,DATA), \
        I, \
        ATTRIBUTE)

#define BOOST_FUSION_ADAPT_STRUCT_C_BASE( \
    TEMPLATE_PARAMS_SEQ,NAME_SEQ,I,PREFIX,ATTRIBUTE,ATTRIBUTE_TUPEL_SIZE) \
                                                                                \
    template< \
        BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS(TEMPLATE_PARAMS_SEQ) \
> \
    struct struct_member<BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ), I> \
    { \
        typedef BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 0, ATTRIBUTE) type; \
                                                                                \
        template<typename Seq> \
        static typename add_reference<type>::type \
        call(Seq& seq) \
        { \
            return seq.PREFIX \
                BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 1, ATTRIBUTE); \
        } \
                                                                                \
        template<typename Seq> \
        static typename add_reference<typename add_const<type>::type>::type \
        call(Seq const& seq) \
        { \
            return seq.PREFIX \
                BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE, 1, ATTRIBUTE); \
        } \
    }; \
    template< \
        BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS(TEMPLATE_PARAMS_SEQ) \
> \
    struct struct_member_name<BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ),I>\
    { \
        typedef const char* type; \
                                                                                \
        static type call() \
        { \
            return BOOST_PP_STRINGIZE(BOOST_PP_TUPLE_ELEM(ATTRIBUTE_TUPEL_SIZE,1,ATTRIBUTE));\
        } \
    };

#define BOOST_FUSION_ADAPT_STRUCT_BASE( \
    TEMPLATE_PARAMS_SEQ,NAME_SEQ,TAG,ATTRIBUTES_SEQ,ATTRIBUTES_CALLBACK) \
                                                                                \
namespace boost \
{ \
    namespace fusion \
    { \
        namespace traits \
        { \
            BOOST_FUSION_ADAPT_STRUCT_TAG_OF_SPECIALIZATION( \
                BOOST_PP_EMPTY(),TEMPLATE_PARAMS_SEQ,NAME_SEQ,TAG) \
            BOOST_FUSION_ADAPT_STRUCT_TAG_OF_SPECIALIZATION( \
                const,TEMPLATE_PARAMS_SEQ,NAME_SEQ,TAG) \
        } \
                                                                                \
        namespace extension \
        { \
            BOOST_PP_SEQ_FOR_EACH_I_R( \
                1, \
                BOOST_FUSION_ADAPT_STRUCT_BASE_UNPACK_AND_CALL, \
                (ATTRIBUTES_CALLBACK,TEMPLATE_PARAMS_SEQ,NAME_SEQ), \
                ATTRIBUTES_SEQ) \
                                                                                \
            template< \
                BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS( \
                    TEMPLATE_PARAMS_SEQ) \
> \
            struct struct_size<BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)> \
              : mpl::int_<BOOST_PP_SEQ_SIZE(ATTRIBUTES_SEQ)> \
            {}; \
        } \
    } \
                                                                                \
    namespace mpl \
    { \
        template<typename> \
        struct sequence_tag; \
                                                                                \
        template< \
            BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS( \
                TEMPLATE_PARAMS_SEQ) \
> \
        struct sequence_tag<BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ)> \
        { \
            typedef fusion::fusion_sequence_tag type; \
        }; \
                                                                                \
        template< \
            BOOST_FUSION_ADAPT_STRUCT_UNPACK_TEMPLATE_PARAMS( \
                TEMPLATE_PARAMS_SEQ) \
> \
        struct sequence_tag< \
            BOOST_FUSION_ADAPT_STRUCT_UNPACK_NAME(NAME_SEQ) const \
> \
        { \
            typedef fusion::fusion_sequence_tag type; \
        }; \
    } \
}

#endif

/*=============================================================================
    Copyright (c) 2001-2007 Joel de Guzman
    Copyright (c) 2005-2006 Dan Marsden
    Copyright (c) 2009-2010 Christopher Schmidt

    Distributed under the Boost Software License, Version 1.0. (See accompanying
    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/

#ifndef BOOST_FUSION_ADAPTED_DETAIL_STRUCT_EXTENSION_HPP
#define BOOST_FUSION_ADAPTED_DETAIL_STRUCT_EXTENSION_HPP

#include <boost/fusion/support/category_of.hpp>

namespace boost { namespace fusion
{
    struct struct_tag;
    struct struct_iterator_tag;
    struct assoc_struct_tag;
    struct assoc_struct_iterator_tag;
    struct fusion_sequence_tag;

    struct assoc_struct_category
      : bidirectional_traversal_tag, associative_tag
    {};

    namespace extension
    {
        struct no_such_member;

        template<typename Seq, int N>
        struct struct_member;

        template<typename Seq, int N>
        struct struct_member_name;

        template<typename Seq, int N>
        struct struct_assoc_key;

        template<typename Seq>
        struct struct_size;
    }
}}

#endif


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