Why can't I use a user defined enumeration type (derived from uint32) as the key type for a containers.Map object?

I have derived a enumeration type from uint32. I want to use this enumeration type as keys in a containers.Map object. However, I get the following error when instantiating the map:
Error using containers.Map
Unsupported key specified. See documentation for valid key types.
This puzzles me! My enumeration class is indeed numeric, so it should be casted internally. Why is this? What could be done (apart from up-casting the keys)?
Thanks in advance,
Per

1 Comment

Conversion works... But it's neither convenient nor elegant. The enumeration is typically defined like this:
classdef hungariancomposers < uint32
enumeration
ZOLTAN (0)
FRANZ (1)
BELA (2)
GYORGY (3)
ERNO (4)
end
end
A conversion approach that works is the following:
keysUNCAST = { hungariancomposers.ZOLTAN hungariancomposers.GYORGY } ;
keysCAST = cellfun( @uint32, keysUNCAST ) ;
values = { 'KODALY', 'LIGETI' } ;
map = containers.Map( keysCAST, values ) ;
But... We really lose the point of enumerations by doing this. Sad!

Sign in to comment.

Answers (0)

Categories

Asked:

on 13 Jun 2013

Community Treasure Hunt

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

Start Hunting!