I would like to store boost::gregorian::date
as key of a boost::unordered_map
but I cannot compile the code as it is missing a proper hash function for this class.
std::string
and store it. I possibly would like to avoid this solution as using string is quite expensive.day()
function and I am not sure if this is really suitable.Is there any other better way to store date or a function exporting date as number?
Implement the hash function for it:
namespace boost { namespace gregorian {
inline size_t hash_value(date const& date)
{
return boost::hash_value(date.julian_day());
}
} } // boost::gregorian
julian_day
is simply the day index since Julian epoch start (whatever that is).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With