[Solved] c++11 implementation of Well Equidistributed Long-period Linear (WELL) without boost?


Here’s how c++11 has made compile time programming (slightly) easier

template <typename UIntType> constexpr bool IsPowerOfTwo(UIntType r)
{
    return (r & (r - 1)) == 0;
}

namespace detail
{
    template<class UIntType, UIntType r, bool>
    struct ModuloHelper;

    template<class UIntType, UIntType r>
    struct ModuloHelper<UIntType, r, true>
    {
        template<class T>
        static T calc(T value)
        {
            return value & (r - 1);
        }
    };

    template<class UIntType, UIntType r>
    struct ModuloHelper<UIntType, r, false>
    {
        template<class T>
        static T calc(T value)
        {
            while (value >= r)
            { value -= r; }

            return value;
        }
    };
}

template<class UIntType, UIntType r>
struct Modulo : detail::ModuloHelper<UIntType, r, IsPowerOfTwo(r)>

10

solved c++11 implementation of Well Equidistributed Long-period Linear (WELL) without boost?