c++ - Calculate some values using template size_t param -


what c++ way calculate values using template params?

template<typename t, size_t size> class threadsafearray { private:     static const size_t block_size = size > 32 ? 16 : 4;     static const size_t mutex_count = size / block_size + 1;     ... }; 

or this

template<typename t, size_t size> class threadsafearray { private:     enum     {         block_size = size > 32 ? 16 : 4,         mutex_count = size / block_size + 1     };         .... }; 

or somehow else?

the enum hack old way provide compile-time computations. used when in class initialization not supportted compilers, static const cannot used. nowadays fixed in modern compilers. preferred way use static const.

check this answer more info.


Comments

Popular posts from this blog

wireshark - USB mapping with python -

c++ - nodejs socket.io closes connection before upgrading to websocket -

Deploying Qt Application on Android is really slow? -