function c = struct2kvpairs(r);

% Function c = struct2kvpairs(r)
% 
% returns a row cell-array c with the key-value pairs of
% each field in given struct r.
% 
% The fields are not ordered.
% 
% Equivalent is the standard m-file namedargs2cell.m.
% 
% 
% (c) 2026 fabien van mook
% 
% 2026.08.20 release of this file within package "fvm-hgeo" under GNU GPLv3+

% This program is free software: you can redistribute it
% and/or modify it under the terms of the GNU General Public
% License as published by the Free Software Foundation, either
% version 3 of the License, or (at your option) any later
% version.
% 
% This program is distributed in the hope that it will be
% useful, but WITHOUT ANY WARRANTY; without even the implied
% warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
% PURPOSE. See the GNU General Public License for more
% details.
% 
% You can read the GNU General Public License on
% <https://www.gnu.org/copyleft/gpl.html>.


c = cell();

if (! isstruct(r)),
  error("struct2kvpairs() expects the input of a struct");
endif;

for [v, k] = r,
  c(end+[1 2]) = {k, v};
endfor;

endfunction;
