[Insight-users] a question regarding itk::hash

Luis Ibanez luis.ibanez at kitware.com
Thu Jul 5 16:19:29 EDT 2007


Hi Kurt,

Using "void *" as a template argument brings too many ambiguities
in the instantiations.

We verified that the code that you posted, does not compile under
Gcc 4.1 or Visual Studio 7.1.

--

That being said, just for the purpose of contorting the hash_map to
work for you, you can instantiate it using "int" as the key type
and then cast the void * to integers when you need to use them
with the hashmap.

Like in:



   typedef int    keytype;
   typedef int    valuetype;

   typedef itk::hash_map< keytype, valuetype > HasMapType;

   HasMapType hashmap;

   void * tempkey = NULL;
   keytype key = (int)tempkey;

   hashmap[ key ] = 2;



The attached example of instantiation of the itk::hash_map<>
class, compiles fine with Visual Studio 7.1 and with GCC 4.1.


Just for sanity check you may want to verify that void* and int
have the same sizeof in your platform/architecture.



    Regards,


       Luis



---------------------
kurt Zhao wrote:
> Hi,
> 
> I am trying to use void* pointer as the type of the key in a itk::hash_map.
> 
> so
> 
> void main ( void )
> 
> {
> itk::hash_map< void*,  int >  mash;
>  void* tempP = NULL ;
>  hash[ tempP ] = 2;
> }
> 
> However, the MSVC .Net gave me the error listed below.
> 
> Any idea to use void* as the type of key in a hash_map?
> 
> Thanks a lot!
> 
> -Kurt
> 
> e:\work\insight\code\common\itk_hashtable.h(581) : error C2064: term
> does not evaluate to a function taking 1 arguments
> 2>        e:\work\insight\code\common\itk_hashtable.h(580) : while
> compiling class template member function
> 'itk::hashtable<Value,Key,HashFcn,ExtractKey,EqualKey,Alloc>::size_type
> itk::hashtable<Value,Key,HashFcn,ExtractKey,EqualKey,Alloc>::bkt_num_key(void 
> 
> *const &,size_t) const'
> 2>        with
> 2>        [
> 2>            Value=std::pair<void *const ,int>,
> 2>            Key=void *,
> 2>            HashFcn=itk::hash<void *>,
> 2>            ExtractKey=std::select1st<std::pair<void *const ,int>>,
> 2>            EqualKey=std::equal_to<void *>,
> 2>            Alloc=std::allocator<char>
> 2>        ]
> 2>        E:\work\Insight\Code\Common\itk_hash_map.h(120) : see
> reference to class template instantiation
> 'itk::hashtable<Value,Key,HashFcn,ExtractKey,EqualKey,Alloc>' being
> compiled
> 2>        with
> 2>        [
> 2>            Value=std::pair<void *const ,int>,
> 2>            Key=void *,
> 2>            HashFcn=itk::hash<void *>,
> 2>            ExtractKey=std::select1st<std::pair<void *const ,int>>,
> 2>            EqualKey=std::equal_to<void *>,
> 2>            Alloc=std::allocator<char>
> 2>        ]
> 2>        e:\work\nirl\roptool\RoPImage.h(343) : see reference to
> class template instantiation 'itk::hash_map<Key,T>' being compiled
> 2>        with
> 2>        [
> 2>            Key=void *,
> 2>            T=int
> 2>        ]
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 

==========================================================


-------------- next part --------------
A non-text attachment was scrubbed...
Name: HashMap.cxx
Type: text/x-c++src
Size: 431 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/insight-users/attachments/20070705/fd6ba537/HashMap.cxx
-------------- next part --------------
PROJECT(HashMap)

FIND_PACKAGE(ITK REQUIRED)
IF(ITK_FOUND)
  INCLUDE(${ITK_USE_FILE})
ENDIF(ITK_FOUND)

ADD_EXECUTABLE(HashMap HashMap.cxx )

TARGET_LINK_LIBRARIES(HashMap ITKCommon)


More information about the Insight-users mailing list