function mustBeUnderlyingType(obj, typename)
%mustBeUnderlyingType  Validate value has specified underlying type.
%
%   mustBeUnderlyingType(VALUE,"TypeName") issues an error if VALUE does
%   not have underlying type equal to "TypeName". TypeName must be a
%   character vector or string scalar.
%
%   Examples:
%   x = zeros(2,2,"single");
%   mustBeUnderlyingType(x,"single")   % OK - underlyingType is single
%
%   x = gpuArray(eye(3,"uint8"));
%   mustBeUnderlyingType(x,"single")   % Error - underlyingType is uint8
%
%   x = dlarray(gpuArray(rand(3)));
%   mustBeUnderlyingType(x,"gpuArray") % Error - underlyingType is double
%
%   x = {1,2,3};
%   mustBeUnderlyingType(x,"double")   % Error - underlyingType is cell
%
%   x = table([1;2],[3;4]);
%   mustBeUnderlyingType(x,"table")    % OK - underlyingType is table
%
%   See also: underlyingType, isUnderlyingType, class.

%   Copyright 2020 The MathWorks, Inc.

if ~isUnderlyingType(obj, typename)
    throwAsCaller(createValidatorException("MATLAB:validators:mustBeUnderlyingType", typename));
end
