using template
- 원래 using 문법이 나오기전에는 typedef를 많이 사용했다 그런데 여기서 typedef는 타입에만 가능하고 템플릿에는 alias가 안된다는 것이다.. 그렇지만 using 문법은 템플릿에대해서도 alias가 가능하다..
예시.
//type alias
using SET = unordered_st;
//template alias..
template<typename T>
using SET = unordered_set<T>;
int main()
{
SET<int> s1;
}
variable template
- 이것은 그냥 variable tmeplate만 보면 필요없어 보이기는 하는데... type_traits 구현의 핵심 문법이다..
template<typename T>
constexpr T pi = static_cast<T>(3.141592);
int main()
{
double area2 = 3 * 3 * pi<float>;
}
- 참고로 constexpr는 컴파일시간에 가능하도록 하는 것이다.
'c++ > 모던c++' 카테고리의 다른 글
meta template(moden c++ 방법) (0) | 2022.05.23 |
---|---|
c++20(concept) (0) | 2022.05.23 |
varidic template (가변인자.. tuple직접구현..) (0) | 2022.05.22 |
c++ 11 가변인자템플릿 varidic template (0) | 2022.04.07 |
전달 참조 forwarding reference (c++17) (0) | 2022.03.29 |