Skip to content

Functors: avoid generating std::integral_constant when a plain int also works

Avoid generating std::integral_constant as argument type in functor code when a plain int also works -- which reduces the load on the compiler, as it reduces the number of template instances that will be generated - and thus reduces the memory requirements for compiling functors.

As an example, the python snippet in_range( 0, M, 1600 ) would end up with 0 and 1600 turned into std::integral_constant<int,0>{} and std::integral_constant<int,1600>{} in the generated C++ code, leading to different in_range overloads being generated for every (integer) numerical value, even if the functor M would be the same.

Note: this particular case (which triggered this fix) could also be fixed by specifying in_range( 0., M, 1600. ) but why impose that burden on the user of in_range -- and in addition, the same also holds for eg SIZE == 2, which this MR also addresses.

Edited by Gerhard Raven

Merge request reports

Loading