<commit_before>// Copyright (c) 2020 Dr. <NAME> and <NAME>
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/

#ifndef TAO_PEGTL_VISIT_HPP
#define TAO_PEGTL_VISIT_HPP

#include <type_traits>

#include "config.hpp"
#include "rule_list.hpp"

namespace TAO_PEGTL_NAMESPACE
{
   namespace internal
   {
      template< typename Type, typename... Types >
      inline constexpr bool contains = ( std::is_same_v< Type, Types > || ... );

      template< typename Rules, typename Todo, typename Done >
      struct filter
      {
         using type = Todo;
      };

      template< typename Rule, typename... Rules, typename... Todo, typename... Done >
      struct filter< rule_list< Rule, Rules... >, rule_list< Todo... >, rule_list< Done... > >
         : filter< rule_list< Rules... >, std::conditional_t< contains< Rule, Todo..., Done... >, rule_list< Todo... >, rule_list< Rule, Todo... > >, rule_list< Done... > >
      {};

      template< typename Rules, typename Todo, typename Done >
      using filter_t = typename filter< Rules, Todo, Done >::type;

      template< typename... >
      struct concat
      {
         using type = rule_list<>;
      };

      template< typename RuleList >
      struct concat< RuleList >
      {
         using type = RuleList;
      };

      template< typename... R0, typename... R1, typename... Tail >
      struct concat< rule_list< R0... >, rule_list< R1... >, Tail... >
         : concat< rule_list< R0..., R1... >, Tail... >
      {};

      template< typename... Ts >
      using concat_t = typename concat< Ts... >::type;

      template< template< typename... > class Func, typename Done, typename... Rules >
      struct visitor
      {
         template< typename... Args >
         static void visit( Args&&... args )
         {
            ( Func< Rules >::visit( args... ), ... );
            using NextDone = concat_t< rule_list< Rules... >, Done >;
            using NextSubs = concat_t< typename Rules::subs_t... >;
            using NextTodo = filter_t< NextSubs, rule_list<>, NextDone >;
            if constexpr( !std::is_same_v< NextTodo, empty_list > ) {
               visit_next< NextDone >( NextTodo(), args... );
            }
         }

      private:
         template< typename NextDone, typename... NextTodo, typename... Args >
         static void visit_next( rule_list< NextTodo... > /*unused*/, Args&&... args )
         {
            visitor< Func, NextDone, NextTodo... >::visit( args... );
         }
      };

   }  // namespace internal

   template< template< typename... > class Func, typename Rule, typename... Args >
   void visit( Args&&... args )
   {
      internal::visitor< Func, rule_list<>, Rule >::visit( args... );
   }

}  // namespace TAO_PEGTL_NAMESPACE

#endif<commit_msg>Reduce number of instantiations<commit_after>// Copyright (c) 2020 Dr. <NAME> and <NAME>
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/

#ifndef TAO_PEGTL_VISIT_HPP
#define TAO_PEGTL_VISIT_HPP

#include <type_traits>

#include "config.hpp"
#include "rule_list.hpp"

namespace TAO_PEGTL_NAMESPACE
{
   namespace internal
   {
      template< typename Type, typename... Types >
      inline constexpr bool contains = ( std::is_same_v< Type, Types > || ... );

      template< typename Rules, typename Todo, typename Done >
      struct filter
      {
         using type = Todo;
      };

      template< typename Rule, typename... Rules, typename... Todo, typename... Done >
      struct filter< rule_list< Rule, Rules... >, rule_list< Todo... >, rule_list< Done... > >
         : filter< rule_list< Rules... >, std::conditional_t< contains< Rule, Todo..., Done... >, rule_list< Todo... >, rule_list< Rule, Todo... > >, rule_list< Done... > >
      {};

      template< typename Rules, typename Todo, typename Done >
      using filter_t = typename filter< Rules, Todo, Done >::type;

      template< typename... >
      struct concat
      {
         using type = empty_list;
      };

      template< typename R >
      struct concat< R >
      {
         using type = R;
      };

      template< typename... R0, typename... R1 >
      struct concat< rule_list< R0... >, rule_list< R1... > >
      {
         using type = rule_list< R0..., R1... >;
      };

      template< typename... Ts >
      using concat_t = typename concat< Ts... >::type;

      template< typename... R0, typename... R1, typename T, typename... Ts >
      struct concat< rule_list< R0... >, rule_list< R1... >, T, Ts... >
         : concat< rule_list< R0..., R1... >, concat_t< T, Ts... > >
      {};

      template< template< typename... > class Func, typename Done, typename... Rules >
      struct visitor
      {
         template< typename... Args >
         static void visit( Args&&... args )
         {
            ( Func< Rules >::visit( args... ), ... );
            using NextDone = concat_t< rule_list< Rules... >, Done >;
            using NextSubs = concat_t< typename Rules::subs_t... >;
            using NextTodo = filter_t< NextSubs, empty_list, NextDone >;
            if constexpr( !std::is_same_v< NextTodo, empty_list > ) {
               visit_next< NextDone >( NextTodo(), args... );
            }
         }

      private:
         template< typename NextDone, typename... NextTodo, typename... Args >
         static void visit_next( rule_list< NextTodo... > /*unused*/, Args&&... args )
         {
            visitor< Func, NextDone, NextTodo... >::visit( args... );
         }
      };

   }  // namespace internal

   template< template< typename... > class Func, typename Rule, typename... Args >
   void visit( Args&&... args )
   {
      internal::visitor< Func, empty_list, Rule >::visit( args... );
   }

}  // namespace TAO_PEGTL_NAMESPACE

#endif
{'fraction_non_alphanumeric': 0.15191842378154166, 'fraction_numerical': 0.004493605254061528, 'mean_word_length': 2.0046728971962615, 'pattern_counts': {'":': 0, '<': 106, '<?xml version=': 0, '>': 106, 'https://': 2, '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': '939714', 'n_tokens_mistral': 1872, 'n_tokens_neox': 1756, 'n_words': 505}