// -*- C++ -*- /** * @file checkpoweroftwo.h * @brief Check statically if a number is a power of two. * @author Emery Berger * @note Copyright (C) 2005 by Emery Berger, University of Massachusetts Amherst. * **/ #ifndef HL_CHECKPOWEROFTWO_H #define HL_CHECKPOWEROFTWO_H /** * @class IsPowerOfTwo * @brief Sets value to 1 iff the template argument is a power of two. * **/ namespace HL { template class IsPowerOfTwo { public: enum { VALUE = (!(Number & (Number - 1)) && Number) }; }; /** * @class CheckPowerOfTwo * @brief Template meta-program: fails if number is not a power of two. * **/ template class CheckPowerOfTwo { public: CheckPowerOfTwo() { static_assert(IsPowerOfTwo::VALUE, "Argument must be a power of two."); } // enum { Verify = HL::sassert::VALUE>::VALUE }; }; } #endif