그리고... 그게 된다면 컴파일 타임에 정규식 검증하고싶음...

그런데 literal string을 컴파일 타임에 넘기는거에서 막힘.


Does C++20 not support string literals as template parameters after all? : r/cpp_questions (reddit.com)

이 링크로부터, C++ 20의 경우 가능한 것 같음.


template <auto N> struct string_litteral { constexpr string_litteral(const char (&str)[N]) { std::copy_n(str, N, value); } char value[N]; }; template <string_litteral> void foo() {} auto main() -> int { foo<"qwerty">(); }

이게 링크에 올라온 예제인데. 컴파일러 20버전 맞춰놓고 빌드하면 돌아감.

그런데 20 이전에는 트릭으로 어떻게 못함? 저거 하자고 20으로 올리는건 좀...