On Tue, Oct 31, 2023 at 12:08 AM Lehua Ding <lehua.d...@rivai.ai> wrote: > > Hi Andrew, > > On 2023/10/31 14:48, Andrew Pinski wrote: > >> +inline > >> +gimple_match_op::gimple_match_op (const gimple_match_cond &cond_in, > >> + code_helper code_in, tree type_in, > >> + tree op0, tree op1, tree op2, tree op3, > >> + tree op4, tree op5) > >> + : cond (cond_in), code (code_in), type (type_in), reverse (false), > >> + num_ops (6) > >> +{ > >> + ops[0] = op0; > >> + ops[1] = op1; > >> + ops[2] = op2; > >> + ops[3] = op3; > >> + ops[4] = op4; > >> + ops[5] = op5; > >> +} > > Hmm, does it make sense to start to use variadic templates for these > > constructors instead of writing them out? > > And we can even add a static_assert to make sure the number of > > arguments is <= MAX_NUM_OPS to make sure they are correct. And use > > std::is_same to make sure we are only passing tree types. > > You mean something like this?: > > template<typename... op_types> > inline > gimple_match_op::gimple_match_op (const gimple_match_cond &cond_in, > code_helper code_in, tree type_in, > op_types... ops) > : cond (cond_in), code (code_in), type (type_in), reverse (false), > num_ops (sizeof...(ops)) > { > static_assert (sizeof...(ops) <= MAX_NUM_OPS); > auto op_list[] = {ops...}; > for (int i = 0; i < sizeof...(ops); i++) > this->ops[i] = op_list[i]; > }
Yes and maybe use tree for the type of op_list instead of auto. I suspect this code was originally written before GCC was written in C++11. Maybe if this code is being compiled with C++20 we could do something like: #include <concepts> template< std::same_as<tree>... op_types> To get a decent error message earlier ... Thanks, Andrew > > -- > Best, > Lehua (RiVAI) > lehua.d...@rivai.ai