<commit_before>//===- llvm/ADT/STLExtras.h - Useful STL related functions ------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains some templates that are useful if you are working with the
// STL at all.
//
// No library is required when using these functions.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_ADT_STLEXTRAS_H
#define LLVM_ADT_STLEXTRAS_H

#include "llvm/Support/Compiler.h"
#include <cstddef> // for std::size_t
#include <cstdlib> // for qsort
#include <functional>
#include <iterator>
#include <memory>
#include <utility> // for std::pair

namespace llvm {

//===----------------------------------------------------------------------===//
//     Extra additions to <functional>
//===----------------------------------------------------------------------===//

template<class Ty>
struct identity : public std::unary_function<Ty, Ty> {
  Ty &operator()(Ty &self) const {
    return self;
  }
  const Ty &operator()(const Ty &self) const {
    return self;
  }
};

template<class Ty>
struct less_ptr : public std::binary_function<Ty, Ty, bool> {
  bool operator()(const Ty* left, const Ty* right) const {
    return *left < *right;
  }
};

template<class Ty>
struct greater_ptr : public std::binary_function<Ty, Ty, bool> {
  bool operator()(const Ty* left, const Ty* right) const {
    return *right < *left;
  }
};

/// An efficient, type-erasing, non-owning reference to a callable. This is
/// intended for use as the type of a function parameter that is not used
/// after the function in question returns.
///
/// This class does not own the callable, so it is not in general safe to store
/// a function_ref.
template<typename Fn> class function_ref;

#if LLVM_HAS_VARIADIC_TEMPLATES

template<typename Ret, typename ...Params>
class function_ref<Ret(Params...)> {
  Ret (*callback)(void *callable, Params ...params);
  void *callable;

  template<typename Callable>
  static Ret callback_fn(void *callable, Params ...params) {
    return (*reinterpret_cast<Callable*>(callable))(
        std::forward<Params>(params)...);
  }

public:
  template<typename Callable>
  function_ref(Callable &&callable)
      : callback(callback_fn<typename std::remove_reference<Callable>::type>),
        callable(reinterpret_cast<void *>(&callable)) {}
  Ret operator()(Params ...params) const {
    return callback(callable, std::forward<Params>(params)...);
  }
};

#else

template<typename Ret>
class function_ref<Ret()> {
  Ret (*callback)(void *callable);
  void *callable;

  template<typename Callable>
  static Ret callback_fn(void *callable) {
    return (*reinterpret_cast<Callable*>(callable))();
  }

public:
  template<typename Callable>
  function_ref(Callable &&callable)
      : callback(callback_fn<typename std::remove_reference<Callable>::type>),
        callable(reinterpret_cast<void *>(&callable)) {}
  Ret operator()() const { return callback(callable); }
};

template<typename Ret, typename Param1>
class function_ref<Ret(Param1)> {
  Ret (*callback)(void *callable, Param1 param1);
  void *callable;

  template<typename Callable>
  static Ret callback_fn(void *callable, Param1 param1) {
    return (*reinterpret_cast<Callable*>(callable))(
        std::forward<Param1>(param1));
  }

public:
  template<typename Callable>
  function_ref(Callable &&callable)
      : callback(callback_fn<typename std::remove_reference<Callable>::type>),
        callable(reinterpret_cast<void *>(&callable)) {}
  Ret operator()(Param1 param1) {
    return callback(callable, std::forward<Param1>(param1));
  }
};

template<typename Ret, typename Param1, typename Param2>
class function_ref<Ret(Param1, Param2)> {
  Ret (*callback)(void *callable, Param1 param1, Param2 param2);
  void *callable;

  template<typename Callable>
  static Ret callback_fn(void *callable, Param1 param1, Param2 param2) {
    return (*reinterpret_cast<Callable*>(callable))(
        std::forward<Param1>(param1),
        std::forward<Param2>(param2));
  }

public:
  template<typename Callable>
  function_ref(Callable &&callable)
      : callback(callback_fn<typename std::remove_reference<Callable>::type>),
        callable(reinterpret_cast<void *>(&callable)) {}
  Ret operator()(Param1 param1, Param2 param2) {
    return callback(callable,
                    std::forward<Param1>(param1),
                    std::forward<Param2>(param2));
  }
};

template<typename Ret, typename Param1, typename Param2, typename Param3>
class function_ref<Ret(Param1, Param2, Param3)> {
  Ret (*callback)(void *callable, Param1 param1, Param2 param2, Param3 param3);
  void *callable;

  template<typename Callable>
  static Ret callback_fn(void *callable, Param1 param1, Param2 param2,
                         Param3 param3) {
    return (*reinterpret_cast<Callable*>(callable))(
        std::forward<Param1>(param1),
        std::forward<Param2>(param2),
        std::forward<Param3>(param3));
  }

public:
  template<typename Callable>
  function_ref(Callable &&callable)
      : callback(callback_fn<typename std::remove_reference<Callable>::type>),
        callable(reinterpret_cast<void *>(&callable)) {}
  Ret operator()(Param1 param1, Param2 param2, Param3 param3) {
    return callback(callable,
                    std::forward<Param1>(param1),
                    std::forward<Param2>(param2),
                    std::forward<Param3>(param3));
  }
};

#endif<commit_msg>Attempt to placate compilers that warn on casts between pointer-to-object and pointer-to-function types.<commit_after>//===- llvm/ADT/STLExtras.h - Useful STL related functions ------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains some templates that are useful if you are working with the
// STL at all.
//
// No library is required when using these functions.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_ADT_STLEXTRAS_H
#define LLVM_ADT_STLEXTRAS_H

#include "llvm/Support/Compiler.h"
#include <cstddef> // for std::size_t
#include <cstdlib> // for qsort
#include <functional>
#include <iterator>
#include <memory>
#include <utility> // for std::pair

namespace llvm {

//===----------------------------------------------------------------------===//
//     Extra additions to <functional>
//===----------------------------------------------------------------------===//

template<class Ty>
struct identity : public std::unary_function<Ty, Ty> {
  Ty &operator()(Ty &self) const {
    return self;
  }
  const Ty &operator()(const Ty &self) const {
    return self;
  }
};

template<class Ty>
struct less_ptr : public std::binary_function<Ty, Ty, bool> {
  bool operator()(const Ty* left, const Ty* right) const {
    return *left < *right;
  }
};

template<class Ty>
struct greater_ptr : public std::binary_function<Ty, Ty, bool> {
  bool operator()(const Ty* left, const Ty* right) const {
    return *right < *left;
  }
};

/// An efficient, type-erasing, non-owning reference to a callable. This is
/// intended for use as the type of a function parameter that is not used
/// after the function in question returns.
///
/// This class does not own the callable, so it is not in general safe to store
/// a function_ref.
template<typename Fn> class function_ref;

#if LLVM_HAS_VARIADIC_TEMPLATES

template<typename Ret, typename ...Params>
class function_ref<Ret(Params...)> {
  Ret (*callback)(intptr_t callable, Params ...params);
  intptr_t callable;

  template<typename Callable>
  static Ret callback_fn(intptr_t callable, Params ...params) {
    return (*reinterpret_cast<Callable*>(callable))(
        std::forward<Params>(params)...);
  }

public:
  template<typename Callable>
  function_ref(Callable &&callable)
      : callback(callback_fn<typename std::remove_reference<Callable>::type>),
        callable(reinterpret_cast<intptr_t>(&callable)) {}
  Ret operator()(Params ...params) const {
    return callback(callable, std::forward<Params>(params)...);
  }
};

#else

template<typename Ret>
class function_ref<Ret()> {
  Ret (*callback)(intptr_t callable);
  intptr_t callable;

  template<typename Callable>
  static Ret callback_fn(intptr_t callable) {
    return (*reinterpret_cast<Callable*>(callable))();
  }

public:
  template<typename Callable>
  function_ref(Callable &&callable)
      : callback(callback_fn<typename std::remove_reference<Callable>::type>),
        callable(reinterpret_cast<intptr_t>(&callable)) {}
  Ret operator()() const { return callback(callable); }
};

template<typename Ret, typename Param1>
class function_ref<Ret(Param1)> {
  Ret (*callback)(intptr_t callable, Param1 param1);
  intptr_t callable;

  template<typename Callable>
  static Ret callback_fn(intptr_t callable, Param1 param1) {
    return (*reinterpret_cast<Callable*>(callable))(
        std::forward<Param1>(param1));
  }

public:
  template<typename Callable>
  function_ref(Callable &&callable)
      : callback(callback_fn<typename std::remove_reference<Callable>::type>),
        callable(reinterpret_cast<intptr_t>(&callable)) {}
  Ret operator()(Param1 param1) {
    return callback(callable, std::forward<Param1>(param1));
  }
};

template<typename Ret, typename Param1, typename Param2>
class function_ref<Ret(Param1, Param2)> {
  Ret (*callback)(intptr_t callable, Param1 param1, Param2 param2);
  intptr_t callable;

  template<typename Callable>
  static Ret callback_fn(intptr_t callable, Param1 param1, Param2 param2) {
    return (*reinterpret_cast<Callable*>(callable))(
        std::forward<Param1>(param1),
        std::forward<Param2>(param2));
  }

public:
  template<typename Callable>
  function_ref(Callable &&callable)
      : callback(callback_fn<typename std::remove_reference<Callable>::type>),
        callable(reinterpret_cast<intptr_t>(&callable)) {}
  Ret operator()(Param1 param1, Param2 param2) {
    return callback(callable,
                    std::forward<Param1>(param1),
                    std::forward<Param2>(param2));
  }
};

template<typename Ret, typename Param1, typename Param2, typename Param3>
class function_ref<Ret(Param1, Param2, Param3)> {
  Ret (*callback)(intptr_t callable, Param1 param1, Param2 param2, Param3 param3);
  intptr_t callable;

  template<typename Callable>
  static Ret callback_fn(intptr_t callable, Param1 param1, Param2 param2,
                         Param3 param3) {
    return (*reinterpret_cast<Callable*>(callable))(
        std::forward<Param1>(param1),
        std::forward<Param2>(param2),
        std::forward<Param3>(param3));
  }

public:
  template<typename Callable>
  function_ref(Callable &&callable)
      : callback(callback_fn<typename std::remove_reference<Callable>::type>),
        callable(reinterpret_cast<intptr_t>(&callable)) {}
  Ret operator()(Param1 param1, Param2 param2, Param3 param3) {
    return callback(callable,
                    std::forward<Param1>(param1),
                    std::forward<Param2>(param2),
                    std::forward<Param3>(param3));
  }
};

#endif
{'fraction_non_alphanumeric': 0.18048058506007314, 'fraction_numerical': 0.012537001567125197, 'mean_word_length': 3.2, 'pattern_counts': {'":': 0, '<': 143, '<?xml version=': 0, '>': 139, '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': '3923141', 'n_tokens_mistral': 3461, 'n_tokens_neox': 3450, 'n_words': 842}