Use ``exprtk`` to determine boundary edges.
For performance of ``exprtk``, it can match almost 80% percent of naive implementation.
However, it would take 1~2 minutes on compiling the program. Any way, it is better than MATLAB's dynamical allocation with each step.

A workaround is use preallocation as ``std::vector`` does in C++, which uses an aggressive way for appending space.