meta_log.hpp 1.0 KB

1234567891011121314151617181920212223242526
  1. /*-----------------------------------------------------------------------------+
  2. Author: Joachim Faulhaber
  3. Copyright (c) 2009-2009: Joachim Faulhaber
  4. +------------------------------------------------------------------------------+
  5. Distributed under the Boost Software License, Version 1.0.
  6. (See accompanying file LICENCE.txt or copy at
  7. http://www.boost.org/LICENSE_1_0.txt)
  8. +-----------------------------------------------------------------------------*/
  9. namespace mini // minimal implementations for example projects
  10. {
  11. // A meta implementation of an the logarithm function on integrals
  12. template <size_t Argument, size_t Base=2>
  13. struct log_{ enum { value = 1 + log_<Argument/Base, Base>::value }; };
  14. template <size_t Base>struct log_<1, Base>{ enum { value = 0 }; };
  15. template <size_t Base>struct log_<0, Base>{ enum { value = 0 }; };
  16. template <size_t Argument>
  17. struct log2_{ enum { value = log_<Argument, 2>::value }; };
  18. template <size_t Argument>
  19. struct power2_{ enum { value = 1 << Argument }; };
  20. } // namespace mini