matlab coder:Can the C++ functions generated for the entry point functions of the "arguments" validation syntax take mergeability into account?

조회 수: 2 (최근 30일)
For example, there is such an entry-point function in matlab that needs to generate C/C++ code, and I have generated several functions that are suitable for "different" types using the following command line, can these functions be merged into one for code simplicity and readability?
function out = useDefault(a,st)%#codegen
arguments
a (1,1) double
st (1,1) struct = struct("name","cuixing",...
"score",100);
end
% Specify the class of the input as struct.
assert(isstruct(st)); % https://www.mathworks.com/help/coder/ug/define-input-properties-programmatically-in-the-matlab-file.html#bq_w7jz-1
% Specify the class and size of the fields.
% assert(isa(st.name,'string')); %https://www.mathworks.com/help/coder/ug/define-string-scalar-inputs.html
assert(isa(st.score,'double'));
out = a + st.score;
end
command line:
codegen -config:lib -c -args {1,struct('name',"zhang",'score',50)} -args {100} -args {20,struct('name',"ab",'score',20)} -report useDefault -lang:c++
Note: I have specified the input multiple times with the "-args" parameter to represent a wider range of input types.
The resulting C++ code then has multiple similar functions for each `-args`, which does not take advantage of the overloading feature in C++ or use the default argument feature inherent in C++, could this be improved?

채택된 답변

Bhargava Hurulagere Sridharamurthy
Hi Cui,
Thanks for the inputs.
"Overloading feature" is unfortunately not supported in MATLAB Coder as of MATLAB 2022b. We've made an internal note of your request so we can look at lifting that limitation in the future.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by