fork download
  1. #include <iostream>
  2.  
  3. template < int... Ints >
  4. struct int_list { };
  5.  
  6. template < char... Chars >
  7. struct char_list { };
  8.  
  9. template < int N, int... Ints >
  10. struct make_int_list_impl : make_int_list_impl< N-1, N-1, Ints... >
  11. { };
  12.  
  13. template < int... Ints >
  14. struct make_int_list_impl< 0, Ints... > {
  15. using type = int_list< Ints... >;
  16. };
  17.  
  18. template < int N >
  19. using make_int_list = typename make_int_list_impl< N >::type;
  20.  
  21. inline bool and_all() { return true; }
  22.  
  23. template < typename First, typename... Args >
  24. inline bool and_all( First first, Args... args ) {
  25. return first && and_all( args... );
  26. }
  27.  
  28. template < char... Chars >
  29. void print( char const * str, char_list< Chars... > chars ) {
  30. print_impl( str, chars, make_int_list< sizeof...(Chars) >() );
  31. }
  32.  
  33. template < char... Chars, int... Ints >
  34. void print_impl( char const * str, char_list< Chars... >, int_list< Ints... > ) {
  35. if( and_all( (str[Ints] == Chars)... ) )
  36. std::cout << str << std::endl;
  37. }
  38.  
  39. int main() {
  40.  
  41. auto prefix = char_list<'a','a','b'>();
  42.  
  43. char const* strs[] = {
  44. "aabfghfghfhfhghfgjdj"
  45. , "abafgjfgjfgjfgjfgjfe"
  46. , "abbklhfhfhdfhhroryor"
  47. , "aabqeprtpeteptpedmfd"
  48. , "aabeererpedpfgpdfgpd"
  49. , "abbrrrtrterterkhjkhj"
  50. };
  51.  
  52. for( auto const * str : strs )
  53. print( str, prefix );
  54. }
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
aabfghfghfhfhghfgjdj
aabqeprtpeteptpedmfd
aabeererpedpfgpdfgpd