Skip to content

Bug in functor grammar when passing vector of ints and vector of bools

When I do:

Rec/run python -i 
from Functors.grammar import python_to_cpp_str 
l = = [1,2,3]
python_to_cpp_str(l)

I get:

std::vector{std::integral_constant<int, 0>{}, std::integral_constant<int, 1>{}, std::integral_constant<int, 2>{}}

This in C++ is an invalid expression as vector is holding different types.

We noticed this issue in the series of MRs (DaVinci!716 (merged)) when we wanted to pass a vector of integer invalid value to a functor i.e. F.VALUE_OR([-1]).

The fix could be changing these lines to:

    if type(obj) == int:
        return 'int{{}}'.format(obj)
    elif type(obj) == bool:
        return 'bool{{}}'.format('true' if obj else 'false')

Should we go ahead and do this (I remember a discussion where we wanted python list to return std::vector rather than std::tuple) : @chasse , @graven ?

FYI: @jzhuo , @erodrigu , @pkoppenb

Edited by Eduardo Rodrigues