Created
April 25, 2017 05:41
-
-
Save jtbandes/1b242290968a44ef74f6af55ca547f90 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
template<int N, char C, char... Cs> struct repeatImpl : repeatImpl<N-1, C, C, Cs...> {}; | |
template<char C, char... Cs> struct repeatImpl<0, C, Cs...> { | |
static constexpr char cs[] = {Cs..., '\0'}; | |
}; | |
template<char C, char... Cs> constexpr char repeatImpl<0, C, Cs...>::cs[]; | |
template<int N, char C> const char (& repeat())[N+1] { | |
return repeatImpl<N, C>::cs; | |
} | |
int main (int argc, char const *argv[]) | |
{ | |
cout << "str: " << repeat<5, 'x'>() << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment