C++ template 3

C++ 템플릿(Template): SFINAE

C++ Template: SFINAE Substitution Failure Is Not An Error SFINAE는 C++ 템플릿 프로그래밍에서 자주 쓰이는 기법입니다. 컴파일러가 알맞은 함수를 추론(deduce) 하는 원리를 이용해, 받는 타입을 제한하거나 타입에 따라 행동을 다르게 할 때 주로 사용하게 됩니다. SFINAE is a technique that is often used in C++ Template Programming. It restrains function parameter types by using the mechanism of how the compiler deduces appropriate overloaded functions and calling the appropriate ..

C++ Reference: std::integer_sequence, std::index_sequence

std::integer_sequence, std::index_sequence Can make integer sequence in compile-time, so it is often used in compile-time indexing. 컴파일 타임에 정수 시퀸스를 가진 녀석을 만들 수 있어, 컴파일 타임 인덱싱 등에 활용되는 녀석입니다. 헤더에 정의되어 있는 클래스입니다. Defined in header template class integer_sequence; template using index_sequence = integer_sequence; std::index_sequence 는 std::integer_sequence의 첫번째 템플릿 파라미터가 std::size_t 로 템플릿 특수화(templa..

C++ 템플릿(Template): CRTP

항상 느끼는 것 이지만, C 나 C++ 개발자들은 정말 성능 변태가 분명합니다. 특히 템플릿을 배우기 시작하는 분들은 느끼시겠지만, 정말 성능 하나만을 위해 변태같은 짓을 하는것을 서슴치 않는 사람들이 바로 C++ 개발자들 입니다. 이번에 소개해드릴 템플릿 패턴은 CRTP 입니다. CRTP 는 동적 다형성(polymorphism), 즉 기반 클래스 포인터에 파생 클래스 객체의 포인터를 대입해 사용하는 것을 피하면서 가상(virtual) 함수의 override 를 흉내내는 템플릿 기법입니다. CRTP 는 템플릿에 의한 정적 다형성 이므로, 가상함수의 호출에 드는 오버헤드 비용을 없엘 수 있습니다. CRTP 의 약자는 Curiously Recursing Template Pattern 으로, 굳이 의역한다면 ..