[Boost.Fusion] Compile-time callbacks.

Hi, I am somewhat new to Boost Fusion and MPI, therefore I apologize if I am asking a trivial question (I wasn't able to the answer). I have a map of <mpl::int_<N>, boost::function> pairs. Each integer is a command, and based on that command I would like call some specific function. However, after debugging through the code, I have realized that the callbacks are not compile time. So, I was wondering if anybody could tell me if there is a way of modifying my code in such a manner that there is no run-time overhead associated with map indexing. Here is an example code. ////////10////////20////////30////////40////////50////////60////////70////////80 int main(int argc, char* argv[]) { boost::function<void (int)> _int_1_; boost::function<void (std::string)> _int_2_; _int_1_ = &fun_1; _int_2_ = &fun_2; { using boost::fusion::map; using boost::mpl::int_; boost::fusion::result_of::make_map<int_<1>, int_<2>, boost::function<void (int)>, boost::function<void (std::string)>
::type fmap;
boost::fusion::at_key< int_<1> >(fmap) = _int_1_; boost::fusion::at_key< int_<1> >(fmap)(5); }

AMDG Vjekoslav Brajkovic wrote:
I am somewhat new to Boost Fusion and MPI, therefore I apologize if I am asking a trivial question (I wasn't able to the answer). I have a map of <mpl::int_<N>, boost::function> pairs. Each integer is a command, and based on that command I would like call some specific function. However, after debugging through the code, I have realized that the callbacks are not compile time. So, I was wondering if anybody could tell me if there is a way of modifying my code in such a manner that there is no run-time overhead associated with map indexing. Here is an example code.
How do you get the argument for the function? The integral key is only known at runtime, so the type of the argument must only be known at runtime, too. Am I missing something? In Christ, Steven Watanabe

On Tue, 29 Jul 2008, Steven Watanabe wrote:
How do you get the argument for the function? The integral key is only known at runtime, so the type of the argument must only be known at runtime, too. Am I missing something?
Here are the two lines: /* * Here, we associate the value with the known key * *boost::mpl::int_<1>*, which is known at the * compile time. */ boost::fusion::at_key< int_<1> >(fmap) = _int_1_; /* And here we pass the argument. */ boost::fusion::at_key< int_<1> >(fmap)(5); As I have sad before, I'm not particularly familiar with MPL/Fusion, so any clarifications are very welcome. For instance, the document specifies: "It is named "fusion" because the library is reminiscent of the "fusion" of compile time meta-programming with runtime programming.", but it does not specify which part is compile and which is run-time. Also the function arguments are irrelevant. Let's say I call: at_key< int_<1> >(fmap)(); I would like this to be translated into: _int_1_(); -Vjeko

On Tue, Jul 29, 2008 at 5:34 PM, Vjekoslav Brajkovic <balkan@cs.washington.edu> wrote:
As I have sad before, I'm not particularly familiar with MPL/Fusion, so any clarifications are very welcome. For instance, the document specifies: "It is named "fusion" because the library is reminiscent of the "fusion" of compile time meta-programming with runtime programming.", but it does not specify which part is compile and which is run-time.
The types are compile-time and the values are run-time. With most fusion containers (say, fusion::vector<int,float>), each element has a compile time type and a value that can be changed at run-time (this is where it differs from MPL). Maps/pairs are a slight departure from the rest in that the first element of a fusion::pair (the key) does not have a value associated with it, only the type. Stjepan

On Tue, 29 Jul 2008, Stjepan Rajko wrote:
On Tue, Jul 29, 2008 at 5:34 PM, Vjekoslav Brajkovic <balkan@cs.washington.edu> wrote:
As I have sad before, I'm not particularly familiar with MPL/Fusion, so any clarifications are very welcome. For instance, the document specifies: "It is named "fusion" because the library is reminiscent of the "fusion" of compile time meta-programming with runtime programming.", but it does not specify which part is compile and which is run-time.
The types are compile-time and the values are run-time. With most fusion containers (say, fusion::vector<int,float>), each element has a compile time type and a value that can be changed at run-time (this is where it differs from MPL). Maps/pairs are a slight departure from the rest in that the first element of a fusion::pair (the key) does not have a value associated with it, only the type.
Yeah, it makes much more sense now. Thanks for the clarification. =) -Vjeko
participants (3)
-
Steven Watanabe
-
Stjepan Rajko
-
Vjekoslav Brajkovic