diff options
author | Shauren <shauren.trinity@gmail.com> | 2015-12-26 00:33:14 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2015-12-26 00:33:14 +0100 |
commit | 921d893c2a82eb6ac0762bf7001df87911b44611 (patch) | |
tree | d3cbce85c60601cbc9b37258d72b943121ee5d2b /src | |
parent | 41d6460c75ce094e8ade92c88b603231aaa8e8a5 (diff) |
Build fix
Diffstat (limited to 'src')
-rw-r--r-- | src/common/Utilities/Containers.h | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/common/Utilities/Containers.h b/src/common/Utilities/Containers.h index df97e342932..5d16576baf2 100644 --- a/src/common/Utilities/Containers.h +++ b/src/common/Utilities/Containers.h @@ -74,34 +74,34 @@ namespace Trinity * Select a random element from a container where each element has a different chance to be selected. * * @param container Container to select an element from - * @param weightExtractor Function retrieving chance of each element in container + * @param weights Chances of each element to be selected, must be in the same order as elements in container * * Note: container cannot be empty */ template <class C> - typename C::const_iterator SelectRandomWeightedContainerElement(C const& container, std::function<double(typename C::value_type const&)> weightExtractor) + typename C::const_iterator SelectRandomWeightedContainerElement(C const& container, std::vector<double> weights) { - std::vector<double> weights; - weights.reserve(container.size()); - std::transform(container.begin(), container.end(), std::back_inserter(weights), weightExtractor); - return SelectRandomWeightedContainerElement(container, weights); + std::discrete_distribution<uint32> dd(weights.begin(), weights.end()); + typename C::const_iterator it = container.begin(); + std::advance(it, dd(SFMTEngine::Instance())); + return it; } /* * Select a random element from a container where each element has a different chance to be selected. * * @param container Container to select an element from - * @param weights Chances of each element to be selected, must be in the same order as elements in container + * @param weightExtractor Function retrieving chance of each element in container * * Note: container cannot be empty */ template <class C> - typename C::const_iterator SelectRandomWeightedContainerElement(C const& container, std::vector<double> weights) + typename C::const_iterator SelectRandomWeightedContainerElement(C const& container, std::function<double(typename C::value_type const&)> weightExtractor) { - std::discrete_distribution<uint32> dd(weights.begin(), weights.end()); - typename C::const_iterator it = container.begin(); - std::advance(it, dd(SFMTEngine::Instance())); - return it; + std::vector<double> weights; + weights.reserve(container.size()); + std::transform(container.begin(), container.end(), std::back_inserter(weights), weightExtractor); + return SelectRandomWeightedContainerElement(container, weights); } /** |