What is most efficient way to validate bitcoin target (difficulty) value in C++ I have two values 

1. h = hash of the block (32 bytes long in memory representation - not hex)
2. bits (uint32_t)


To make the calculation easier we create a function difficulty such that:

auto d = difficulty(bits)


Now what is the best way to create such a difficulty function that, I believe should, return a 256 bit value?

Then I am thinking casting both h and d values into an array of type uint64_t and compare all 4 elements from msb (bit 255) to make sure the condition holds.

Is there a better way for comparing as well?
Bitcoin Core has its own arith_uint256 class for calculations on 256-bit unsigned integers.  Its code to convert "bits" (so-called compact format) to arith_uint256 can be found in arith_uint256::SetCompact in the file arith_uint256.cpp.  

So you could always just use its code directly.  This might be a good idea because if your version differs in any way from their behavior (e.g. rounding errors), you could disagree with Bitcoin Core on the validity of a block.  If your version is in a widely-used client, this would fork the block chain.