C++/Effective Modern C++
-
[Effective Modern C++] Type deduction : autoC++/Effective Modern C++ 2021. 12. 27. 15:41
형식 연역 (Type deduction)은 소스코드에서 특정한 코드가 어떤 것으로 바뀌는 것 입니다. 여기서 '특정한 코드'란 template, auto, decltype 등 이 있으며 바뀌게 되는 '어떤 것' 에는 자료형부터, 함수, 람다식 등이 있습니다. 이전 글에서, template에 대한 형식 연역을 살펴보았습니다. 몇 가지 예외를 제외하면, 특정한 규칙에 따라 연역이 직관적으로 이루어짐을 볼 수 있었습니다. auto는 template과 유사합니다. 한 가지 경우만 제외하면, template와 동일하게 연역됩니다. 이번 글에서는 auto의 형식 연역에 대하여 살펴보도록 하겠습니다. 함수 템플릿은 일반적으로 아래와 같이 표현되고, 호출됩니다. //Declaration template void fun..
-
[Effective Modern C++] Type deduction : TemplateC++/Effective Modern C++ 2021. 12. 21. 09:27
형식 연역 (Type deduction)은 소스코드에서 특정한 코드가 어떤 것으로 바뀌는 것 입니다. 여기서 '특정한 코드'란 template, auto, decltype 등 이 있으며 바뀌게 되는 '어떤 것' 에는 자료형부터, 함수, 람다식 등이 있습니다. 형식 연역은 특정한 규칙에 의거하여 이루어집니다. 개발자가 추론한 것과 컴파일러가 실제로 연역한 것이 다를 수 있기 때문에, 이 규칙을 확실히 이해해야 합니다. 귀찮고, 복잡하다고 안 쓰기에는 template과 auto는 굉장히 유용한 기능이기 때문입니다. 이번 글에서는 template의 형식 연역에 대하여 살펴보도록 하겠습니다. 함수 템플릿은 보통 아래와 같은 형태로 선언되고, 호출됩니다. //Declaration template void func..