fusion sequences, type erasure across translation units
Hello,
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.
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
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
( new make_fusion_seq_tag<...>::type ); // this was the generating .cpp The function returns smart_ptr
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
participants (2)
-
Hicham Mouline
-
Steven Watanabe