diff --git a/include/pcg_extras.hpp b/include/pcg_extras.hpp index ec3e569..d4c710d 100644 --- a/include/pcg_extras.hpp +++ b/include/pcg_extras.hpp @@ -135,7 +135,7 @@ operator<<(std::basic_ostream& out, pcg128_t value) } if (highpart != 0 || desired_width > 16) out << highpart; - CharT oldfill; + CharT oldfill = '\0'; if (highpart != 0) { out.width(16); oldfill = out.fill('0'); @@ -156,7 +156,7 @@ operator<<(std::basic_ostream& out, pcg128_t value) constexpr auto BASE = pcg128_t(10ULL); do { auto div = value / BASE; - auto mod = uint32_t(value - (div * BASE)); + auto mod = char(value % BASE); *(--pos) = '0' + mod; value = div; } while(value != pcg128_t(0ULL)); @@ -220,7 +220,7 @@ operator<<(std::basic_ostream&out, uint8_t value) template std::basic_istream& -operator>>(std::basic_istream& in, uint8_t target) +operator>>(std::basic_istream& in, uint8_t& target) { uint32_t value = 0xdecea5edU; in >> value; @@ -393,7 +393,7 @@ SrcIter uneven_copy_impl( constexpr bitcount_t SCALE = SRC_SIZE / DEST_SIZE; size_t count = 0; - src_t value; + src_t value = 0; while (dest_first != dest_last) { if ((count++ % SCALE) == 0) @@ -483,10 +483,10 @@ void generate_to_impl(SeedSeq&& generator, DestIter dest, generator.generate(buffer, buffer+FROM_ELEMS); uneven_copy(buffer, dest, dest+size); } else { - uint32_t* buffer = (uint32_t*) malloc(GEN_SIZE * FROM_ELEMS); + uint32_t* buffer = static_cast(malloc(GEN_SIZE * FROM_ELEMS)); generator.generate(buffer, buffer+FROM_ELEMS); uneven_copy(buffer, dest, dest+size); - free(buffer); + free(static_cast(buffer)); } } @@ -531,13 +531,14 @@ template void shuffle(Iter from, Iter to, RandType&& rng) { typedef typename std::iterator_traits::difference_type delta_t; + typedef typename std::remove_reference::type::result_type result_t; auto count = to - from; while (count > 1) { - delta_t chosen(bounded_rand(rng, count)); + delta_t chosen = delta_t(bounded_rand(rng, result_t(count))); --count; --to; using std::swap; - swap(*(from+chosen), *to); + swap(*(from + chosen), *to); } } @@ -620,11 +621,11 @@ std::ostream& operator<<(std::ostream& out, printable_typename) { const char *implementation_typename = typeid(T).name(); #ifdef __GNUC__ int status; - const char* pretty_name = + char* pretty_name = abi::__cxa_demangle(implementation_typename, NULL, NULL, &status); if (status == 0) out << pretty_name; - free((void*) pretty_name); + free(static_cast(pretty_name)); if (status == 0) return out; #endif diff --git a/include/pcg_random.hpp b/include/pcg_random.hpp index 59bc480..4550b3f 100644 --- a/include/pcg_random.hpp +++ b/include/pcg_random.hpp @@ -75,6 +75,7 @@ #ifndef PCG_RAND_HPP_INCLUDED #define PCG_RAND_HPP_INCLUDED 1 +#include #include #include #include @@ -82,6 +83,7 @@ #include #include #include +#include #include #include #include @@ -321,7 +323,7 @@ class specific_stream { specific_stream() = default; specific_stream(itype specific_seq) - : inc_((specific_seq << 1) | itype(1U)) + : inc_(itype(specific_seq << 1) | itype(1U)) { // Nothing (else) to do. } @@ -380,7 +382,7 @@ class engine : protected output_mixin, static constexpr result_type max() { - return ~result_type(0UL); + return result_type(~result_type(0UL)); } protected: @@ -422,7 +424,7 @@ class engine : protected output_mixin, static itype distance(itype cur_state, itype newstate, itype cur_mult, itype cur_plus, itype mask = ~itype(0U)); - itype distance(itype newstate, itype mask = ~itype(0U)) const + itype distance(itype newstate, itype mask = itype(~itype(0U))) const { return distance(state_, newstate, multiplier(), increment(), mask); } @@ -1360,7 +1362,10 @@ bool operator==(const extended(lhs); auto& base_rhs = static_cast(rhs); return base_lhs == base_rhs - && !memcmp((void*) lhs.data_, (void*) rhs.data_, sizeof(lhs.data_)); + && !std::equal( + std::begin(lhs.data_), std::end(lhs.data_), + std::begin(rhs.data_) + ); } template