Ok, I guess you solution is better for it uses "static_for_each" which
would turn into statically generated code.
But we may skip pushing stuff into a vector by doing
std::size_t hash = 0;
static_for_each( p, [&] ( const channel_t& c )
{
boost::hash_combine(hash, c);
});
return hash;
Do we agree with this?
Regards.
2013/3/26 Christian Henning
On Tue, Mar 26, 2013 at 9:51 AM, Harg Tholan
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-w...
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
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
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost