<commit_before>#ifndef MANIFOLDS_FUNCTIONS_SIMPLIFY_HH
#define MANIFOLDS_FUNCTIONS_SIMPLIFY_HH

#include "tuple_util.hh"
#include <boost/type_traits/is_same.hpp>

namespace manifolds {
  //Default, don't do anything
  template <class A, class ForEnableIf = void>
  struct Simplification
  {
    typedef A type;

    static type Combine(A a)
    {
      return a;
    }
  };

  template <template <class...> class Variadic,
	    class ... Args1, class ... Args2>
  struct Simplification<Variadic<Variadic<Args1...>, Args2...> >
  {
    typedef Variadic<Args1..., Args2...> type;

    static type Combine(Variadic<Variadic<Args1...>, Args2...> v)
    {
      auto t =
	std::tuple_cat(std::get<0>(v.GetFunctions()).GetFunctions(),
		       remove_element<0>(v.GetFunctions()));
      return {t};
    }
  };

  template <template <class...> class Variadic,
	    class ... Args1, class ... Args2>
  struct Simplification<Variadic<Variadic<Args1...>,
			   Variadic<Args2...>>>
  {
    typedef Variadic<Args1..., Args2...> type;

    static type Combine(Variadic<Variadic<Args1...>,
			Variadic<Args2...>> input)
    {
      return type(std::tuple_cat(std::get<0>(input),
				 std::get<1>(input)));
    }
  };

  template <class F>
  auto Simplify(F f, F)
  {
    return f;
  }

  template <class F, class G>
  auto Simplify(F f, G)
  {
    return Simplify(Simplification<F>::Combine(f), f);
  }

  template <class F>
  auto Simplify(F f)
  {
    return Simplify(Simplification<F>::Combine(f), f);
  }
}

#endif<commit_msg>Added optional simplification debug messages and IsVariadic template metafunction<commit_after>#ifndef MANIFOLDS_FUNCTIONS_SIMPLIFY_HH
#define MANIFOLDS_FUNCTIONS_SIMPLIFY_HH

#include "tuple_util.hh"
#include <boost/type_traits/is_same.hpp>
#include <iostream>

namespace manifolds {
  //Default, don't do anything
  template <class A, class ForEnableIf = void>
  struct Simplification
  {
    typedef A type;

    static type Combine(A a)
    {
      return a;
    }
  };

  template <template<class...>class Variadic, class...>
  struct IsVariadic : std::false_type{};

  template <template<class...>class V, class ... Fs,
	    class ... Fs2>
  struct IsVariadic<V, V<Fs...>,Fs2...> : std::true_type{};

  template <template <class...> class Variadic,
	    class ... Args1, class ... Args2>
  struct Simplification<
    Variadic<Variadic<Args1...>, Args2...>,
    typename std::enable_if<
      !IsVariadic<Variadic,Args2...>::value>::type>
  {
    typedef Variadic<Args1..., Args2...> type;

    static type Combine(Variadic<Variadic<Args1...>, Args2...> v)
    {
      auto t =
	std::tuple_cat(std::get<0>(v.GetFunctions()).GetFunctions(),
		       remove_element<0>(v.GetFunctions()));
      return {t};
    }
  };

  template <template <class...> class Variadic,
	    class ... Args1, class ... Args2>
  struct Simplification<Variadic<Variadic<Args1...>,
			   Variadic<Args2...>>>
  {
    typedef Variadic<Args1..., Args2...> type;

    static type Combine(Variadic<Variadic<Args1...>,
			Variadic<Args2...>> input)
    {
      auto t1 =
	std::get<0>(input.GetFunctions()).GetFunctions();
      auto t2 =
	std::get<1>(input.GetFunctions()).GetFunctions();
      return type(std::tuple_cat(t1, t2));
    }
  };

  template <class F>
  auto Simplify(F f, F)
  {
#ifdef PRINT_SIMPLIFIES
    std::cout << "Done: " << f << std::endl;
#endif
    return f;
  }

  template <class F, class G>
  auto Simplify(F f, G)
  {
#ifdef PRINT_SIMPLIFIES
    std::cout << "Simplifying: " << f << std::endl;
#endif
    return Simplify(Simplification<F>::Combine(f), f);
  }

  template <class F>
  auto Simplify(F f)
  {
#ifdef PRINT_SIMPLIFIES
    std::cout << "Simplifying: " << f << std::endl;
#endif
    return Simplify(Simplification<F>::Combine(f), f);
  }
}

#endif
{'fraction_non_alphanumeric': 0.1633139227104288, 'fraction_numerical': 0.012440444679724723, 'mean_word_length': 3.1210468920392587, 'pattern_counts': {'":': 0, '<': 88, '<?xml version=': 0, '>': 70, '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': '7336543', 'n_tokens_mistral': 1425, 'n_tokens_neox': 1328, 'n_words': 284}