Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <iostream>
- namespace detail {
- template<char...Chars>
- bool checkSize(const std::string& s) {
- return sizeof...(Chars) <= s.size();;
- }
- template<size_t N, char C, char...Chars>
- struct StartsWith {
- static const bool apply(const std::string& s) {
- return s[N] == C && StartsWith<N + 1, Chars...>::apply(s);
- }
- };
- template<size_t N, char C>
- struct StartsWith<N, C> {
- static const bool apply(const std::string& s) {
- return s[N] == C;
- }
- };
- } // detail
- template<char...Chars>
- bool startsWith(const std::string& s) {
- return detail::checkSize<Chars...>(s) && detail::StartsWith<0, Chars...>::apply(s);
- }
- int main() {
- std::string x = "zlonejzlejsi";
- std::cout << startsWith<'z','l','o'>(x) << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement