personalrobotics / chimera

:snake: A CLI tool for generating Boost.Python/pybind11 bindings from C/C++
BSD 3-Clause "New" or "Revised" License
13 stars 1 forks source link

Generating template variable #297

Closed jslee02 closed 4 years ago

jslee02 commented 4 years ago
#include <type_traits>
namespace chimera_test {
template <typename T>
constexpr bool template_var = std::true_type::value;  // [1]
constexpr bool specialized_var = template_var<int>;   // [2]
}

Generated binding for this source:

m.attr("template_var") = chimera_test::template_var;       // [3] invalid binding
m.attr("specialized_var") = chimera_test::specialized_var  // [4] valid binding
m.attr("template_var") = chimera_test::template_var;       // [5] invalid binding

[3] is generated when template_var in [1] is visited, but the binding shouldn't be generated because the template variable is not specialized.

[4] and [5] are generated when specialized_var in [2] is visited. [4] is okay because specialized_var is just a global variable being assigned with a specialized template variable (i.e., template_var<int>). However, [5] should be either not generated or be m.attr("template_var_int") = chimera_test::template_var<int>, which I'm not sure which one would be the right way. If we need to generate [5], note that the variable name should be mangled name (e.g., template_var_int) unless specified by config (also, we don't have a way to specify properties for variables).

298 changes Chimera to skip generating [3] and [5].