Provide easy type-safe hardware layout tree traversal mechanism
Summary
Just copying https://gitlab.cern.ch/cmsgemonline/cmsgemos/-/issues/42#note_3440296 here, so the idea does not get lost, even if the implementation is delayed.
"""
The two elements described in the original description are introduced in !28 (merged). While developing it, I had a new idea to provide easier type-safe traversal of the tree. One could enable the following syntax (starting from a link
):
link.children() | type_switch(
[] (const optohybrid_fpga_node& oh_fpga) {
std::cout << "this is the fpga" << std::endl;
},
[] (const vfat_node& vfat) {
std::cout << "this is a vfat" << std::endl;
},
[] (const gbtx_node& gbtx) {
std::cout << "this is a gbtx" << std::endl;
}
)
type_switch
would perform the required dynamic_cast
under the hood and call the relevant lambda for each node. It could also have an overload taking a node*
as first argument, type_switch(node*, lambdas...)
.
In many cases type_switch
would be more powerful alternative to filter_nodes
, but the latter is still useful because it requires less typing and returns a valid range that can be passed to <algorithm>
& co.
Thoughts, comments, ideas? Please add
[The