Boost logo

Boost Users :

Subject: Re: [Boost-users] fusion sequences, type erasure across translation units
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2010-01-29 10:38:21


AMDG

Hicham Mouline wrote:
> I have a .cpp file which a sort of top level driver.
> I have say 100 different
> struct param_i {...};
> where 1<=i<=100
>
> Each param_i is defined in a param_i.hpp and param_i.cpp invokes metafunctions to obtain
> typedef fusion< variant< vector<double>, triplet<double>, pair<double>, double>,
> variant<...>, ...,
> variant<...> >
> seq_i_t;
> this sequence type is visible only in the param_i.cpp, not the header file. Generation of this sequence is
> The size of these sequences = number of members of param_i.
>

Are the variants all the same? If they are, you can just use an array.

> The toplevel driver and other .cpp need to move instances of these types around to other .cpp.
> To avoid having the compiler call the metafunctions for these middle translation units, but only at the generating .cpp and at the consuming .cpp, I created a tag
>
> struct fusion_seq_tag {};
>
> typedef <typename Arg>
> struct make_fusion_seq_i {
> typedef <undefined> type;
> };
>
> typedef <typename Arg>
> struct make_fusion_seq_tag {
> typedef typename make_fusion_seq_i<Arg>::type base_type;
> struct type : fusion_seq_tag, base_type {
> type(...) : base_type(...) {}
> };
> };
>
> return smart_ptr<fusion_seq_tag>( new make_fusion_seq_tag<...>::type );
>
> // this was the generating .cpp
> The function returns smart_ptr<fusion_seq_tag> which can move around in other .cpp without any metaprogramming
> until reaching the consuming .cpp
>
> Is this type erasure?
>

No.

> I don't know how I can get the actual type back in the consuming .cpp if I don't know the originator but if I know only the shape of the fusion sequence. How to dynamic cast the type back to its unerased type?
>

You can't unless you know type.

> If I know the originator .cpp then I would know the exact fusion sequence and therefore I would just dynamic_cast the fusion_seq_tag.
>

You can't dynamic_cast, because fusion_seq_tag is not a polymorphic type.

In Christ,
Steven Watanabe


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