Is it possible to overload subsref
and subsasgn
to allow non-integer types for index value?
h = Hash; #% a custom hash class to manage my data
h(100) = 'data'; #% integer is fine, if index > 0
h{'string'} #% but this fails
??? Cell contents reference from a
non-cell array object.
Can one hack it somehow?
Exact solution:
There are several annoyances in containers.Map
, which can be solved by making a custom class which inherits it:
classdef Hash < containers.Map
# fun
end
In such class one can implement various types of keys (not just one!!) and convenience methods for the user operations. Also it is possible to redefine subsref
and subsasgn
to work with curly braces and multiple indices. Nice!