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

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -