[Solved] Template to determine the size in bytes of various variables
Solution in C++14, assuming I understood what you meant: template <class Container> constexpr auto byte_size(const Container& container) { using std::begin; using std::end; return (end(container) – begin(container)) * sizeof(container[0]); } Note that this will work even if the container is empty, since sizeof does not evaluate its operand. It won’t work for std::vector<bool> though—guess you’ll have … Read more