Does sizeof(T) * CHAR_BIT guarantee bit size?

Viewed 530

There doesn't appear to be any library function for calculating the size of a type in bits.

Am I right to assume that this can be done in the following way?

#include <climits>

template <typename T>
size_t Size_In_Bits(){
    return sizeof(T) * CHAR_BIT;
}

Will this always give back the amount of bits that can be targeted on a type?

2 Answers
Related