#include <iostream>
template < int... Ints >
struct int_list { };
template < char... Chars >
struct char_list { };
template < int N, int... Ints >
struct make_int_list_impl : make_int_list_impl< N-1, N-1, Ints... >
{ };
template < int... Ints >
struct make_int_list_impl< 0, Ints... > {
using type = int_list< Ints... >;
};
template < int N >
using make_int_list = typename make_int_list_impl< N >::type;
inline bool and_all() { return true; }
template < typename First, typename... Args >
inline bool and_all( First first, Args... args ) {
return first && and_all( args... );
}
template < char... Chars >
void print( char const * str, char_list< Chars... > chars ) {
print_impl( str, chars, make_int_list< sizeof...(Chars) >() );
}
template < char... Chars, int... Ints >
void print_impl( char const * str, char_list< Chars... >, int_list< Ints... > ) {
if( and_all( (str[Ints] == Chars)... ) )
std::cout << str << std::endl;
}
int main() {
auto prefix = char_list<'a','a','b'>();
char const* strs[] = {
"aabfghfghfhfhghfgjdj"
, "abafgjfgjfgjfgjfgjfe"
, "abbklhfhfhdfhhroryor"
, "aabqeprtpeteptpedmfd"
, "aabeererpedpfgpdfgpd"
, "abbrrrtrterterkhjkhj"
};
for( auto const * str : strs )
print( str, prefix );
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdGVtcGxhdGUgPCBpbnQuLi4gSW50cyA+CnN0cnVjdCBpbnRfbGlzdCB7IH07Cgp0ZW1wbGF0ZSA8IGNoYXIuLi4gQ2hhcnMgPgpzdHJ1Y3QgY2hhcl9saXN0IHsgfTsKCnRlbXBsYXRlIDwgaW50IE4sIGludC4uLiBJbnRzID4Kc3RydWN0IG1ha2VfaW50X2xpc3RfaW1wbCA6IG1ha2VfaW50X2xpc3RfaW1wbDwgTi0xLCBOLTEsIEludHMuLi4gPgp7IH07Cgp0ZW1wbGF0ZSA8IGludC4uLiBJbnRzID4Kc3RydWN0IG1ha2VfaW50X2xpc3RfaW1wbDwgMCwgSW50cy4uLiA+IHsKICAgIHVzaW5nIHR5cGUgPSBpbnRfbGlzdDwgSW50cy4uLiA+OyAKfTsKCnRlbXBsYXRlIDwgaW50IE4gPgp1c2luZyBtY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