2 // Copyright 2005-2009 Daniel James.
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #if !defined(BOOST_UNORDERED_TEST_HELPERS_RANDOM_VALUES_HEADER)
7 #define BOOST_UNORDERED_TEST_HELPERS_RANDOM_VALUES_HEADER
9 #include "./generators.hpp"
11 #include "./metafunctions.hpp"
13 #include <boost/detail/select_type.hpp>
16 template <class X> struct unordered_generator_set
18 typedef BOOST_DEDUCED_TYPENAME X::value_type value_type;
20 random_generator type_;
22 unordered_generator_set(random_generator type) : type_(type) {}
24 template <class T> void fill(T& x, std::size_t len)
26 value_type* value_ptr = 0;
29 for (std::size_t i = 0; i < len; ++i) {
30 value_type value = generate(value_ptr, type_);
33 type_ == generate_collisions ? random_value(5) + 1 : 1;
35 for (std::size_t j = 0; j < count; ++j) {
42 template <class X> struct unordered_generator_map
44 typedef BOOST_DEDUCED_TYPENAME X::key_type key_type;
45 typedef BOOST_DEDUCED_TYPENAME X::mapped_type mapped_type;
47 random_generator type_;
49 unordered_generator_map(random_generator type) : type_(type) {}
51 template <class T> void fill(T& x, std::size_t len)
53 key_type* key_ptr = 0;
54 mapped_type* mapped_ptr = 0;
56 for (std::size_t i = 0; i < len; ++i) {
57 key_type key = generate(key_ptr, type_);
60 type_ == generate_collisions ? random_value(5) + 1 : 1;
62 for (std::size_t j = 0; j < count; ++j) {
63 x.push_back(std::pair<key_type const, mapped_type>(
64 key, generate(mapped_ptr, type_)));
71 struct unordered_generator_base
72 : public boost::detail::if_true<test::is_set<X>::value>::
73 BOOST_NESTED_TEMPLATE then<test::unordered_generator_set<X>,
74 test::unordered_generator_map<X> >
79 struct unordered_generator : public unordered_generator_base<X>::type
81 typedef BOOST_DEDUCED_TYPENAME unordered_generator_base<X>::type base;
83 unordered_generator(random_generator const& type = default_generator)
90 struct random_values : public test::list<BOOST_DEDUCED_TYPENAME X::value_type>
94 explicit random_values(std::size_t count,
95 test::random_generator const& generator = test::default_generator)
97 fill(count, generator);
100 void fill(std::size_t count,
101 test::random_generator const& generator = test::default_generator)
103 test::unordered_generator<X> gen(generator);
104 gen.fill(*this, count);