c++ - How to build up a directed graph at compile time? -


i want build directed graph in c++11 @ compile time.

example: have threads , queues , want build up:

+-------+            +---------+            +-------+ | f_gen | -> qgen -> | f_check | -> qout -> | f_out | +-------+            +---------+    ^       +-------+                           |         |                          \|/        |                           |         |                         qproc       |                           |         |                          \|/        |                           |         |                      +-----------+  |                      | f_process | /                      +-----------+ 

please note example: solution should handle directed graphs of every node / edge type.

i want write maybe like:

make_directed_graph<queue, thread>( // queues {    // id, type of queue, queue size    { 0, std::string, 100 }, // qgen    { 1, int, 250 },         // qproc    { 2, std::string, 500 }  // qout }, // threads {     // fn, thread cnt, in queues, out queues    { f_gen, 5, {}, { qref(0) } }, // id 1: qgen     { f_check, 30, { qref(0) }, { qref(1), qref(2) }}, // ids of queues    { f_process, 75, { qref(1) }, { qref(2) }},    { f_out, 12, { qref(2) }, {} } }); 

please note idea - other possibility of writing down fine me.

i managed implement make_tree function. can used

make_tree< arexp, int >(      { '+', { 1, 2, { '*', { 3, 4, 5 } } } } ) 

there 1 big difference here: nodes , edges can created 'on fly' - there no need reference existing one.

the biggest problem directed graph how reference object / structure / part defined earlier. like: how reference queue when defining threads (or vice verse).

my questions:

  1. is possible define directed graph @ compile time?
  2. if so, can please give me hint how implement it?

it's possible, because identify objects pointers, , pointers valid non-type template arguments.

queue<std::string> qgen(100); // no need id, have &qgen. //  *do* need pass queue type figure out type of &qgen. thread<void, nullptr, std::string, &qgen> f_gen(5); 

of course, can't define cyclic graph way.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -