본문 바로가기

Programming/C&C++&C#

modern C++ using 사용법

728x90
반응형
#include <iostream>

using namespace std;

// 1. type alias 
using DWORD = int ;
using FP = void(*)(int);

// 2. template alias
template<typename T>
class Point
{
    T x, y;
};
template<typename T>
using PT = Point<T>; 


// 3. 템플릿 인자 고정
template<typename T, typename U>
using Duo = pair<T, U>;
template<typename T>
using I_Duo = pair<int, T>;

// 4. 복잡한 문법 단순화
template<typename T>
using remove_pointer_t = typename remove_pointer<T>::type ;

int main (void)
{
    DWORD     n ;     // int n
    FP        p ;     // void(*p)(int)

    Point<int> p1;
    PT<int> p2;
    I_Duo<int> p3;
    p3.first = 10;
    p3.second = 10;
    cout << p3.first << " " << p3.second << endl;
}
반응형

'Programming > C&C++&C#' 카테고리의 다른 글

modern C++ begin/end  (0) 2019.12.15
modern C++ noexcept  (0) 2019.12.15
modern C++ static_assert  (0) 2019.12.15
modern C++ 11/14 iteral & type, auto & decltype  (0) 2019.12.15
modern C++  (0) 2019.12.15