<commit_before>
#ifndef SELECTOR_H_
#define SELECTOR_H_

#include <cassert>
#include <functional>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <type_traits>

namespace evolve
{

    namespace Selector
    {
        template<typename genome, size_t num>
        typename std::enable_if<!std::is_pointer<genome>::value>::type
        top(std::vector<genome>& population,
                        std::function<float(const genome&)> evaluator)
        {
            static_assert( num >=1, "Selector must leave at least 1 individual in the population");
            assert(population.size() >= num );

            std::sort(population.begin(), population.end(),
                      [&](const genome& left,
                          const genome& right)
                      {
                          return evaluator(left) > evaluator(right);
                      });

            auto location = population.begin();
            std::advance(location, num);

            population.erase(location, population.end());
        }


        template<typename genome, size_t num>
        typename std::enable_if<std::is_pointer<genome>::value>::type
        top(std::vector<genome>& population,
                        std::function<float(const genome&)> evaluator)
        {
            static_assert( num >=1, "Selector must leave at least 1 individual in the population");
            assert(population.size() >= num );

            std::sort(population.begin(), population.end(),
                      [&](const genome& left,
                          const genome& right)
                      {
                          return evaluator(left) > evaluator(right);
                      });

            auto location = population.begin();
            std::advance(location, num);

            //Assume the pointer points to dynamically allocated memory
            for (auto iter = location; iter != population.end(); ++iter)
            {
                delete *iter;
            }

            population.erase(location, population.end());
        }
    }
}

#endif<commit_msg>Removed selector via enable_if in favor of dispatch<commit_after>
#ifndef SELECTOR_H_
#define SELECTOR_H_

#include <cassert>
#include <functional>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <type_traits>

namespace evolve
{

    namespace Selector
    {

        template<typename genome, size_t num>
        void topHelper(std::vector<genome>& population,
                       std::function<float(const genome&)> evaluator,
                       std::false_type genomeIsPointer)
        {
            static_assert( num >=1, "Selector must leave at least 1 individual in the population");
            assert(population.size() >= num );

            std::sort(population.begin(), population.end(),
                      [&](const genome& left,
                          const genome& right)
                      {
                          return evaluator(left) > evaluator(right);
                      });

            auto location = population.begin();/*!< Detailed description after the member */
            std::advance(location, num);

            population.erase(location, population.end());
        }


        template<typename genome, size_t num>
        void topHelper(std::vector<genome>& population,
                       std::function<float(const genome&)> evaluator,
                       std::true_type genomeIsPointer)
        {
            static_assert( num >=1, "Selector must leave at least 1 individual in the population");
            assert(population.size() >= num );

            std::sort(population.begin(), population.end(),
                      [&](const genome& left,
                          const genome& right)
                      {
                          return evaluator(left) > evaluator(right);
                      });

            auto location = population.begin();
            std::advance(location, num);

            //Assume the pointer points to dynamically allocated memory
            for (auto iter = location; iter != population.end(); ++iter)
            {
                delete *iter;
            }

            population.erase(location, population.end());
        }


        /*!
         * Select the top 'num' individuals from the population. If genome is a
         * pointer, the individuals not selected are deleted.
         */
        template<typename genome, size_t num>
        void top(std::vector<genome>& population,
                 std::function<float(const genome&)> evaluator)
        {
            topHelper<genome, num>(population, evaluator, typename std::is_pointer<genome>::type());
        }


    }
}

#endif
{'fraction_non_alphanumeric': 0.10834213305174234, 'fraction_numerical': 0.001689545934530095, 'mean_word_length': 1.7615160349854226, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3285100', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1105, 'n_words': 301}