Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72216 - in sandbox/bloom_filter/trunk: . include test
From: cpp.cabrera_at_[hidden]
Date: 2011-05-27 12:44:56


Author: alejandro
Date: 2011-05-27 12:44:54 EDT (Fri, 27 May 2011)
New Revision: 72216
URL: http://svn.boost.org/trac/boost/changeset/72216

Log:
Swapped std::tuple, std::tuple_element, and std::tuple_size for
        mpl::vector, mpl::at_c, and mpl::size.
Added:
   sandbox/bloom_filter/trunk/.gitignore (contents, props changed)
Text files modified:
   sandbox/bloom_filter/trunk/include/bloom.hpp | 34 +++++++++++++++-------------------
   sandbox/bloom_filter/trunk/test/boost_test.cpp | 4 ++--
   2 files changed, 17 insertions(+), 21 deletions(-)

Added: sandbox/bloom_filter/trunk/.gitignore
==============================================================================
--- (empty file)
+++ sandbox/bloom_filter/trunk/.gitignore 2011-05-27 12:44:54 EDT (Fri, 27 May 2011)
@@ -0,0 +1,3 @@
+*.o
+*.a
+boost_test

Modified: sandbox/bloom_filter/trunk/include/bloom.hpp
==============================================================================
--- sandbox/bloom_filter/trunk/include/bloom.hpp (original)
+++ sandbox/bloom_filter/trunk/include/bloom.hpp 2011-05-27 12:44:54 EDT (Fri, 27 May 2011)
@@ -7,7 +7,10 @@
  */
 #include <boost/config.hpp>
 #include <bitset>
-#include <tuple>
+
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/size.hpp>
+#include <boost/mpl/at.hpp>
 
 #include <hash.hpp>
 
@@ -18,64 +21,57 @@
 struct apply_hash
 {
   static void insert(const T& t, std::bitset<Size>& _bits) {
- typedef typename std::tuple_element<N, HashFunctions>::type Hash;
+ typedef typename boost::mpl::at_c<HashFunctions, N>::type Hash;
     _bits[Hash::hash(t) % Size] = true;
     apply_hash<N-1, T, Size, HashFunctions>::insert(t, _bits);
   }
 
   static bool contains(const T& t, const std::bitset<Size>& _bits) {
- typedef typename std::tuple_element<N, HashFunctions>::type Hash;
+ typedef typename boost::mpl::at_c<HashFunctions, N>::type Hash;
     return (_bits[Hash::hash(t) % Size] &&
             apply_hash<N-1, T, Size, HashFunctions>::contains(t, _bits));
   }
 };
 
-/**
- * \todo: clean up tuples here, as well
- */
 template <typename T,
           size_t Size,
           class HashFunctions>
 struct apply_hash<0, T, Size, HashFunctions>
 {
   static void insert(const T& t, std::bitset<Size>& _bits) {
- typedef typename std::tuple_element<0, HashFunctions>::type Hash;
+ typedef typename boost::mpl::at_c<HashFunctions, 0>::type Hash;
     _bits[Hash::hash(t) % Size] = true;
   }
 
   static bool contains(const T& t, const std::bitset<Size>& _bits) {
- typedef typename std::tuple_element<0, HashFunctions>::type Hash;
+ typedef typename boost::mpl::at_c<HashFunctions, 0>::type Hash;
     return (_bits[Hash::hash(t) % Size]);
   }
 };
 
-/**
- * \todo: clean-up use of tuple here. Not all compilers support std::tuple
- */
 template <typename T,
           size_t Size,
- class HashFunctions = std::tuple<MurmurHash3<T, 3>,
- MurmurHash3<T, 5>,
- MurmurHash3<T, 7> > >
+ class HashFunctions = boost::mpl::vector<MurmurHash3<T, 3>,
+ MurmurHash3<T, 5>,
+ MurmurHash3<T, 7> > >
 class bloom_filter {
   typedef std::bitset<Size> Bitset;
 
 public:
   bloom_filter() {}
 
- // \todo: need to add compiler check for constexpr
   BOOST_CONSTEXPR size_t size() const {
     return Size;
   }
 
   void insert(const T& t) {
- static const unsigned size = std::tuple_size<HashFunctions>::value - 1;
- apply_hash<size, T, Size, HashFunctions>::insert(t, bits);
+ static const unsigned N = boost::mpl::size<HashFunctions>::value - 1;
+ apply_hash<N, T, Size, HashFunctions>::insert(t, bits);
   }
 
   bool contains(const T& t) const {
- static const unsigned size = std::tuple_size<HashFunctions>::value - 1;
- return apply_hash<size, T, Size, HashFunctions>::contains(t, bits);
+ static const unsigned N = boost::mpl::size<HashFunctions>::value - 1;
+ return apply_hash<N, T, Size, HashFunctions>::contains(t, bits);
   }
 
   bool operator[](const T& t) const {

Modified: sandbox/bloom_filter/trunk/test/boost_test.cpp
==============================================================================
--- sandbox/bloom_filter/trunk/test/boost_test.cpp (original)
+++ sandbox/bloom_filter/trunk/test/boost_test.cpp 2011-05-27 12:44:54 EDT (Fri, 27 May 2011)
@@ -6,7 +6,7 @@
 #include <boost/test/unit_test.hpp>
 
 BOOST_AUTO_TEST_CASE(defaultConstructor) {
- typedef std::tuple<
+ typedef boost::mpl::vector<
     OHash <int, 2>,
     OHash<int, 3>,
     OHash<int, 5>,
@@ -147,7 +147,7 @@
 }
 
 BOOST_AUTO_TEST_CASE(collisionBenchmark) {
- typedef std::tuple<
+ typedef boost::mpl::vector<
     OHash <size_t, 2>,
     OHash<size_t, 3>,
     OHash<size_t, 5>,


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk