I have a wrapper class around uint32_t:
class IPv4
{
uint32_t octets_;
public:
operator uint32_t() {return octets;}
};
Also I have a structure inherited from IPv4 class:
struct routerID : public IPv4
{};
I want to create an unordered_map:
std::unordered_map<RouterID, std::string> routers;
But I’ve got an error: attempting to reference a deleted function.
Is there a way to make it working without explicitly defining hash_function and == for my IPv4 class?
hash<IPv4>, delegating to existing hash, would be a one-liner.using RouterID = std::uint32_t;, then yes, you could say it is in factuint32_t. Otherwise, it's a distinct type, no matter how simple.uint32_tremoves some of the advantages you gain by having a custom type in the first place, IMO.