<commit_before>#include <stdexcept>
#include <string>

#include "function.hxx"
#include "variable.hxx"


//////////////////
// Constructors //
//////////////////

function::function() : _args(1)
{
  _args[0] = std::make_shared<variable>();
  _fptr = [](std::vector<double> & args) { return args.front(); };
}

function::function(fptr_t fptr, std::vector<double> args)
  : _fptr(fptr), _args(args.size(), nullptr)
{
  unsigned size(args.size());
  for (unsigned i = 0; i < size; ++i) {
    _args[i] = std::make_shared<variable>(args[i]);
  }
}

function::function(fptr_t fptr, unsigned num, double * args)
  : _fptr(fptr), _args(num, nullptr)
{
  for (unsigned i = 0; i < num; ++i) {
    _args[i] = std::make_shared<variable>(args[i]);
  }
}

function::function(fptr_t fptr, fnbase_ptr_vec & args)
  : _fptr(fptr), _args(args) {}

function::function(fptr_t fptr, unsigned num, fnbase_ptr * args)
  : _fptr(fptr), _args(args, args + num) {}

function::function(fptr_t fptr, std::vector<fnbase*> & args)
  : _fptr(fptr), _args(args.size(), nullptr)
{
  unsigned size(args.size());
  for (unsigned i = 0; i < size; ++i) {
    _args[i] = fnbase_ptr(args[i]);
  }
}

function::function(fptr_t fptr, unsigned num, fnbase * args)
  : _fptr(fptr), _args(num)
{
  for (unsigned i = 0; i < num; ++i) {
    _args[i] = fnbase_ptr(&args[i]);
  }
}

function::function(const function & other)
  : _fptr(other._fptr), _args(other._args) {}

function::~function() {}

///////////////
// Operators //
///////////////

auto function::operator=(const function & other) -> function &
{
  if (this != &other) {
    _fptr = other._fptr;
    _args = other._args;
  }
  return *this;
}

bool function::operator==(const function & other) const
{
  if (other._args == _args and
      other._fptr == _fptr)
    return true;
  else
    return false;
}

bool function::operator!=(const function & other) const
{
  return not (*this == other);
}

function::operator double () const
{
  std::vector<double> args;
  args.reserve(_args.size());
  for (auto arg_ptr : _args) {
    args.push_back(*arg_ptr);	// arg_ptr is fnbase_ptr
  }
  return _fptr(args);
}

/////////////
// Methods //
/////////////

void function::replace(const unsigned idx, fnbase * arg)
{
  if (idx >= _args.size())
    throw std::out_of_range("Index out of range: "<commit_msg>Simple simplification in function::operator==(..)<commit_after>#include <stdexcept>
#include <string>

#include "function.hxx"
#include "variable.hxx"


//////////////////
// Constructors //
//////////////////

function::function() : _args(1)
{
  _args[0] = std::make_shared<variable>();
  _fptr = [](std::vector<double> & args) { return args.front(); };
}

function::function(fptr_t fptr, std::vector<double> args)
  : _fptr(fptr), _args(args.size(), nullptr)
{
  unsigned size(args.size());
  for (unsigned i = 0; i < size; ++i) {
    _args[i] = std::make_shared<variable>(args[i]);
  }
}

function::function(fptr_t fptr, unsigned num, double * args)
  : _fptr(fptr), _args(num, nullptr)
{
  for (unsigned i = 0; i < num; ++i) {
    _args[i] = std::make_shared<variable>(args[i]);
  }
}

function::function(fptr_t fptr, fnbase_ptr_vec & args)
  : _fptr(fptr), _args(args) {}

function::function(fptr_t fptr, unsigned num, fnbase_ptr * args)
  : _fptr(fptr), _args(args, args + num) {}

function::function(fptr_t fptr, std::vector<fnbase*> & args)
  : _fptr(fptr), _args(args.size(), nullptr)
{
  unsigned size(args.size());
  for (unsigned i = 0; i < size; ++i) {
    _args[i] = fnbase_ptr(args[i]);
  }
}

function::function(fptr_t fptr, unsigned num, fnbase * args)
  : _fptr(fptr), _args(num)
{
  for (unsigned i = 0; i < num; ++i) {
    _args[i] = fnbase_ptr(&args[i]);
  }
}

function::function(const function & other)
  : _fptr(other._fptr), _args(other._args) {}

function::~function() {}

///////////////
// Operators //
///////////////

auto function::operator=(const function & other) -> function &
{
  if (this != &other) {
    _fptr = other._fptr;
    _args = other._args;
  }
  return *this;
}

bool function::operator==(const function & other) const
{
  return (other._args == _args and other._fptr == _fptr);
}

bool function::operator!=(const function & other) const
{
  return not (*this == other);
}

function::operator double () const
{
  std::vector<double> args;
  args.reserve(_args.size());
  for (auto arg_ptr : _args) {
    args.push_back(*arg_ptr);	// arg_ptr is fnbase_ptr
  }
  return _fptr(args);
}

/////////////
// Methods //
/////////////

void function::replace(const unsigned idx, fnbase * arg)
{
  if (idx >= _args.size())
    throw std::out_of_range("Index out of range: "
{'fraction_non_alphanumeric': 0.2137454073913983, 'fraction_numerical': 0.002593473092716663, 'mean_word_length': 3.4457252641690683, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 25, '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': '4504654', 'n_tokens_mistral': 1709, 'n_tokens_neox': 1697, 'n_words': 362}