Hi,

I'm sorry, but I have too little time to comment more extensively on this subject (other duties demand attention). Below you'll find an algorithm, that chooses a proper value of n from where to start the log2<> algorithm presented earlier. It does not depend on <limits> and it should always produce a value that has the correct properties. Feel free to refine it as you see fit. You could use it like this:

template<unsigned long x, int n = detail::choose_n<>::value>
struct static_log2 {/*...*/};

-Vesa

#include <iostream>

template<int n = 16>
struct choose_n {
private:
enum {c = 1ul<<n && !(1ul<<n<<n)};
public:
enum {value = c ? n : choose_n<(c ? 0 : n*2)>::value};
};

template<>
struct choose_n<0> {
enum {value = 0};
};


_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to