|
Boost : |
Subject: Re: [boost] [gil] Pixel Hasher
From: Christian Henning (chhenning_at_[hidden])
Date: 2013-03-26 10:18:47
On Tue, Mar 26, 2013 at 9:51 AM, Harg Tholan <hargtholan_at_[hidden]> wrote:
> Do you mean that unordered_map can automatically instantiate a hashing
> function for any type of pixel? I have tried this:
Ok, I see I was wrong. I simple solution is provided here:
http://stackoverflow.com/questions/10405030/c-unordered-map-fail-when-used-with-a-vector-as-key
Taking that you can create the following:
template< typename Pixel >
struct pixel_hasher
{
std::size_t operator()( const Pixel& p ) const
{
typedef channel_type<Pixel>::type channel_t;
vector<channel_t> v;
static_for_each( p, [&] ( const channel_t& c )
{
v.push_back( c );
});
return boost::hash_range( v.begin(), v.end() );
}
};
typedef rgb8_pixel_t pixel_t;
pixel_t p( 1,2,3);
unordered_map< pixel_t, int, pixel_hasher< pixel_t > > n;
n[p] = 99;
Hope this helps.
Christian
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk