andyarvanitis / purescript-native-cpp-ffi

C++ foreign export implementations for the standard library
MIT License
21 stars 8 forks source link

findIndexImpl ffi question #4

Closed iomeone closed 5 years ago

iomeone commented 5 years ago

hi, I have a little quesion on the code .

exports["findIndexImpl"] = [](const boxed& just_) -> boxed {
    return  [=](const boxed& nothing_) -> boxed {
        return [=](const boxed& f_) -> boxed {
            return [=](const boxed& xs_) -> boxed {
                const auto& xs = unbox<array_t>(xs_);
                int len = xs.size();
                for (auto i = 0; i < len; i++) {

                    if (unbox<bool> (f_(boxed(xs[i])) ))
                    {
                        return just_(i);
                    }
                };
                return nothing_;
            };
        };
    };
};

if (unbox<bool> (f_(boxed(xs[i])) )) this line of code , I can also write it as if (unbox<bool> (f_(xs[i]) )) which can compile and run without problem. (windows vs2017 with c++ 14 standard) So it's suggest that the compiler can convert xs[i] to boxed(xs[i]) , am I right? and why was that?

thank you for your time!

andyarvanitis commented 5 years ago

Yes, that's correct. Since xs is an array of boxed, then x[i] is already a boxed.

iomeone commented 5 years ago

thank you ~