<commit_before>// This file is distributed under the BSD License.
// See "license.txt" for details.
// Copyright 2009-2012, <NAME> (<EMAIL>)
// Copyright 2009-2014, <NAME> (<EMAIL>)
// http://www.chaiscript.com


#ifndef CHAISCRIPT_PROXY_FUNCTIONS_HPP_
#define CHAISCRIPT_PROXY_FUNCTIONS_HPP_


#include <algorithm>
#include <cassert>
#include <functional>
#include <memory>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <vector>

#include "../chaiscript_defines.hpp"
#include "boxed_cast.hpp"
#include "boxed_cast_helper.hpp"
#include "boxed_value.hpp"
#include "proxy_functions_detail.hpp"
#include "type_info.hpp"
#include "dynamic_object.hpp"

namespace chaiscript {
class Type_Conversions;
namespace exception {
class bad_boxed_cast;
struct arity_error;
}  // namespace exception
}  // namespace chaiscript

namespace chaiscript
{
  class Boxed_Number;
  struct AST_Node;

  typedef std::shared_ptr<AST_Node> AST_NodePtr;

  namespace dispatch
  {
    class Param_Types
    {
      public:
        Param_Types()
        {}

        Param_Types(std::vector<std::pair<std::string, Type_Info>> t_types)
          : m_types(std::move(t_types))
        {
          update_has_types();
        }

        void push_front(std::string t_name, Type_Info t_ti)
        {
          m_types.emplace(m_types.begin(), std::move(t_name), std::move(t_ti));
          update_has_types();
        }

        bool operator==(const Param_Types &t_rhs) const
        {
          return m_types == t_rhs.m_types;
        }

        bool match(const std::vector<Boxed_Value> &vals, const Type_Conversions &t_conversions) const
        {
          if (!m_has_types) return true;
          if (vals.size() != m_types.size()) return false;

          for (size_t i = 0; i < vals.size(); ++i)
          {
            const auto &name = m_types[i].first;
            if (!name.empty()) {
              const auto &bv = vals[i];

              if (bv.get_type_info().bare_equal(m_doti))
              {
                try {
                  const Dynamic_Object &d = boxed_cast<const Dynamic_Object &>(bv, &t_conversions);
                  return name == "Dynamic_Object" || d.get_type_name() == name;
                } catch (const std::bad_cast &) {
                  return false;
                } 
              } else {
                const auto &ti = m_types[i].second;
                if (!ti.is_undef())
                {
                  if (!bv.get_type_info().bare_equal(ti)) {
                    return false;
                  }
                } else {
                  return false;
                }
              }
            }
          }

          return true;
        }

        const std::vector<std::pair<std::string, Type_Info>> &types() const
        {
          return m_types;
        }

      private:
        void update_has_types()
        {
          for (const auto &type : m_types)
          {
            if (!type.first.empty())
            {
              m_has_types = true;
              return;
            }
          }

          m_has_types = false;
        }

        std::vector<std::pair<std::string, Type_Info>> m_types;
        bool m_has_types = false;
        Type_Info m_doti = user_type<Dynamic_Object>();

    };<commit_msg>Fix g++ 4.6 initializers<commit_after>// This file is distributed under the BSD License.
// See "license.txt" for details.
// Copyright 2009-2012, <NAME> (<EMAIL>)
// Copyright 2009-2014, <NAME> (<EMAIL>)
// http://www.chaiscript.com


#ifndef CHAISCRIPT_PROXY_FUNCTIONS_HPP_
#define CHAISCRIPT_PROXY_FUNCTIONS_HPP_


#include <algorithm>
#include <cassert>
#include <functional>
#include <memory>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <vector>

#include "../chaiscript_defines.hpp"
#include "boxed_cast.hpp"
#include "boxed_cast_helper.hpp"
#include "boxed_value.hpp"
#include "proxy_functions_detail.hpp"
#include "type_info.hpp"
#include "dynamic_object.hpp"

namespace chaiscript {
class Type_Conversions;
namespace exception {
class bad_boxed_cast;
struct arity_error;
}  // namespace exception
}  // namespace chaiscript

namespace chaiscript
{
  class Boxed_Number;
  struct AST_Node;

  typedef std::shared_ptr<AST_Node> AST_NodePtr;

  namespace dispatch
  {
    class Param_Types
    {
      public:
        Param_Types()
          : m_has_types(false),
            m_doti(user_type<Dynamic_Object>())
        {}

        Param_Types(std::vector<std::pair<std::string, Type_Info>> t_types)
          : m_types(std::move(t_types))
          : m_has_types(false),
            m_doti(user_type<Dynamic_Object>())
        {
          update_has_types();
        }

        void push_front(std::string t_name, Type_Info t_ti)
        {
          m_types.emplace(m_types.begin(), std::move(t_name), std::move(t_ti));
          update_has_types();
        }

        bool operator==(const Param_Types &t_rhs) const
        {
          return m_types == t_rhs.m_types;
        }

        bool match(const std::vector<Boxed_Value> &vals, const Type_Conversions &t_conversions) const
        {
          if (!m_has_types) return true;
          if (vals.size() != m_types.size()) return false;

          for (size_t i = 0; i < vals.size(); ++i)
          {
            const auto &name = m_types[i].first;
            if (!name.empty()) {
              const auto &bv = vals[i];

              if (bv.get_type_info().bare_equal(m_doti))
              {
                try {
                  const Dynamic_Object &d = boxed_cast<const Dynamic_Object &>(bv, &t_conversions);
                  return name == "Dynamic_Object" || d.get_type_name() == name;
                } catch (const std::bad_cast &) {
                  return false;
                } 
              } else {
                const auto &ti = m_types[i].second;
                if (!ti.is_undef())
                {
                  if (!bv.get_type_info().bare_equal(ti)) {
                    return false;
                  }
                } else {
                  return false;
                }
              }
            }
          }

          return true;
        }

        const std::vector<std::pair<std::string, Type_Info>> &types() const
        {
          return m_types;
        }

      private:
        void update_has_types()
        {
          for (const auto &type : m_types)
          {
            if (!type.first.empty())
            {
              m_has_types = true;
              return;
            }
          }

          m_has_types = false;
        }

        std::vector<std::pair<std::string, Type_Info>> m_types;
        bool m_has_types;
        Type_Info m_doti;

    };
{'fraction_non_alphanumeric': 0.11618195376584638, 'fraction_numerical': 0.005369127516778523, 'mean_word_length': 1.8475583864118896, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6954398', 'n_tokens_mistral': 2175, 'n_tokens_neox': 2051, 'n_words': 421}