반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
using namespace std;
 
template<typename T>
T f(T a) 
    return a + 1
}
 
 
class A {                            //f 함수 테스트시 A 를 제외하고 생각하면 된다
public:
};
 
template <typename ... Types>
void s1(char cc, Types ... args)
{
 
}
 
template <typename ... Types>
void s1(int cc, Types ... args)
{
 
}
 
template <typename ... Types>
void s1(A cc, Types ... args)
{
 
}
 
template <typename ... Types>
void foo(Types ... args)        //받는건 가변인자로 다 받는데
{
 
    s1(args...);                    //인자 첫번째 타입에 따라 s1 함수가 호출 된다
    //s1(f(args)...);                    //개별 인자들에 +1 을 다 한다음 기반 parameter pack 을 넘긴다
}
 
int main(int argc, char* argv[])
{
    foo('s', A(), 3);
    foo(A(), 's'3);
    foo(12.0f, 3);
    return 0;
}
 
 
cs
반응형

'프로그래밍(Programming) > c++, 11, 14 , 17, 20' 카테고리의 다른 글

[Modern C++] std::move , 간단 예시  (0) 2022.03.03
std::forward  (0) 2022.03.03
std::map::emplace_hint  (0) 2021.03.21
C++ 캐스팅 Static, Dynamic cast  (0) 2020.04.27
std::remove_reference  (0) 2019.12.31

+ Recent posts