From f02cc7775daf4f00dfbe4dbbfba7561dc5519146 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sat, 16 May 2009 13:38:37 +0000 Subject: [PATCH] Long term fix for the incorrect length of prime list. Merged revisions 52658,52669,52673,52711 via svnmerge from https://svn.boost.org/svn/boost/trunk ........ r52658 | danieljames | 2009-04-29 11:05:17 +0100 (Wed, 29 Apr 2009) | 1 line Fix the length of the prime number list. ........ r52669 | danieljames | 2009-04-29 22:43:41 +0100 (Wed, 29 Apr 2009) | 3 lines Don't test prime_list::length on Visual C++. Checking the array size doesn't seem to work on it. ........ r52673 | danieljames | 2009-04-30 06:08:40 +0100 (Thu, 30 Apr 2009) | 1 line Revert changes to unordered, as the test fails on most compilers. ........ r52711 | danieljames | 2009-05-01 21:50:32 +0100 (Fri, 01 May 2009) | 5 lines Use a preprocessor sequence for the primes. This feels like overkill but it seems to be the most reliable way to ensure that the length is correct. I obviously can't be trusted to get it right, and the template hack seems to prevent Boost.Range from working. ........ [SVN r53043] --- include/boost/unordered/detail/hash_table.hpp | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/include/boost/unordered/detail/hash_table.hpp b/include/boost/unordered/detail/hash_table.hpp index 04696176..f64e3e83 100644 --- a/include/boost/unordered/detail/hash_table.hpp +++ b/include/boost/unordered/detail/hash_table.hpp @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include @@ -76,18 +78,25 @@ namespace boost { static std::ptrdiff_t const length; }; - template - std::size_t const prime_list_template::value[] = { - 5ul, 11ul, 17ul, 29ul, 37ul, 53ul, 67ul, 79ul, - 97ul, 131ul, 193ul, 257ul, 389ul, 521ul, 769ul, - 1031ul, 1543ul, 2053ul, 3079ul, 6151ul, 12289ul, 24593ul, - 49157ul, 98317ul, 196613ul, 393241ul, 786433ul, - 1572869ul, 3145739ul, 6291469ul, 12582917ul, 25165843ul, - 50331653ul, 100663319ul, 201326611ul, 402653189ul, 805306457ul, - 1610612741ul, 3221225473ul, 4294967291ul }; +#define BOOST_UNORDERED_PRIMES \ + (5ul)(11ul)(17ul)(29ul)(37ul)(53ul)(67ul)(79ul) \ + (97ul)(131ul)(193ul)(257ul)(389ul)(521ul)(769ul) \ + (1031ul)(1543ul)(2053ul)(3079ul)(6151ul)(12289ul)(24593ul) \ + (49157ul)(98317ul)(196613ul)(393241ul)(786433ul) \ + (1572869ul)(3145739ul)(6291469ul)(12582917ul)(25165843ul) \ + (50331653ul)(100663319ul)(201326611ul)(402653189ul)(805306457ul) \ + (1610612741ul)(3221225473ul)(4294967291ul) template - std::ptrdiff_t const prime_list_template::length = 40; + std::size_t const prime_list_template::value[] = { + BOOST_PP_SEQ_ENUM(BOOST_UNORDERED_PRIMES) + }; + + template + std::ptrdiff_t const prime_list_template::length + = BOOST_PP_SEQ_SIZE(BOOST_UNORDERED_PRIMES); + +#undef BOOST_UNORDERED_PRIMES typedef prime_list_template prime_list;