<commit_before>#ifndef INC_METTLE_DRIVER_FILTERS_HPP
#define INC_METTLE_DRIVER_FILTERS_HPP

#include <functional>
#include <regex>
#include <vector>

#include "filters_core.hpp"

namespace mettle {

class name_filter_set {
public:
  using value_type = std::regex;
  using container_type = std::vector<value_type>;
  using iterator = container_type::const_iterator;

  name_filter_set() = default;
  name_filter_set(const std::initializer_list<value_type> &i) : filters_(i) {}

  filter_result operator ()(const test_name &name, const attributes &) const;

  void insert(const value_type &item) {
    filters_.push_back(item);
  }

  void insert(value_type &&item) {
    filters_.push_back(std::move(item));
  }

  bool empty() const {
    return filters_.empty();
  }

  size_t size() const {
    return filters_.size();
  }

  iterator begin() const {
    return filters_.begin();
  }

  iterator end() const {
    return filters_.end();
  }
private:
  container_type filters_;
};

struct attr_filter_item {
  std::string attribute;
  std::function<bool(const attr_instance *)> func;
};

inline attr_filter_item
has_attr(std::string name) {
  return {std::move(name), [](const attr_instance *attr) -> bool {
    return attr;
  }};
}

inline attr_filter_item
has_attr(std::string name, std::string value) {
  auto f = [value = std::move(value)](const attr_instance *attr) -> bool {
    return attr && attr->value.count(value);
  };
  return {std::move(name), std::move(f)};
}

inline attr_filter_item
operator !(attr_filter_item filter) {
  auto f = [func = std::move(filter.func)](const attr_instance *attr) -> bool {
    return !func(attr);
  };
  return {std::move(filter.attribute), std::move(f)};
}

class attr_filter {
public:
  using value_type = attr_filter_item;
  using container_type = std::vector<attr_filter_item>;
  using iterator = container_type::const_iterator;

  attr_filter() = default;
  attr_filter(const std::initializer_list<value_type> &i) : filters_(i) {}

  filter_result operator ()(const test_name &, const attributes &attrs) const;
<commit_msg>Be explicit about converting pointers to bool (fixes an MSVC warning)<commit_after>#ifndef INC_METTLE_DRIVER_FILTERS_HPP
#define INC_METTLE_DRIVER_FILTERS_HPP

#include <functional>
#include <regex>
#include <vector>

#include "filters_core.hpp"

namespace mettle {

class name_filter_set {
public:
  using value_type = std::regex;
  using container_type = std::vector<value_type>;
  using iterator = container_type::const_iterator;

  name_filter_set() = default;
  name_filter_set(const std::initializer_list<value_type> &i) : filters_(i) {}

  filter_result operator ()(const test_name &name, const attributes &) const;

  void insert(const value_type &item) {
    filters_.push_back(item);
  }

  void insert(value_type &&item) {
    filters_.push_back(std::move(item));
  }

  bool empty() const {
    return filters_.empty();
  }

  size_t size() const {
    return filters_.size();
  }

  iterator begin() const {
    return filters_.begin();
  }

  iterator end() const {
    return filters_.end();
  }
private:
  container_type filters_;
};

struct attr_filter_item {
  std::string attribute;
  std::function<bool(const attr_instance *)> func;
};

inline attr_filter_item
has_attr(std::string name) {
  return {std::move(name), [](const attr_instance *attr) -> bool {
    return attr != nullptr;
  }};
}

inline attr_filter_item
has_attr(std::string name, std::string value) {
  auto f = [value = std::move(value)](const attr_instance *attr) -> bool {
    return attr && attr->value.count(value);
  };
  return {std::move(name), std::move(f)};
}

inline attr_filter_item
operator !(attr_filter_item filter) {
  auto f = [func = std::move(filter.func)](const attr_instance *attr) -> bool {
    return !func(attr);
  };
  return {std::move(filter.attribute), std::move(f)};
}

class attr_filter {
public:
  using value_type = attr_filter_item;
  using container_type = std::vector<attr_filter_item>;
  using iterator = container_type::const_iterator;

  attr_filter() = default;
  attr_filter(const std::initializer_list<value_type> &i) : filters_(i) {}

  filter_result operator ()(const test_name &, const attributes &attrs) const;

{'fraction_non_alphanumeric': 0.132858837485172, 'fraction_numerical': 0.0, 'mean_word_length': 4.997155049786628, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 27, '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': '951906', 'n_tokens_mistral': 1411, 'n_tokens_neox': 1379, 'n_words': 317}