복잡한 그림을 수행하는 몇 가지 기능이 있습니다.Variadic 템플릿 루프, 비 재귀
someFunction<&Brush::xPos1, &Brush::xPos2, &Brush::xPos3, &Brush::xPos4>()
그리고 컴파일러는이 같은 생성 할 : [의사에]
template<typename fields...> // field names of Brush class
void someFunction(){
for(very large loop){
Brush brush = getBrush();
int x;
foreach(field : fields){ // <--- this somehow should be replaced
x = brush.*field;
brush.update(x);
}
}
}
이
[1 목록] 내가 전화
void someFunction(){
for(very large loop){
Brush brush = getBrush();
int x;
x = brush.xPos1;
brush.update(x);
x = brush.xPos2;
brush.update(x);
x = brush.xPos3;
brush.update(x);
x = brush.xPos4;
brush.update(x);
}
}
[2
목록을 ]I mea n, 나는 foreach (field : fields)를 없애고 싶다.
이 가변적 템플릿 루프 구현을 찾았지만 재귀 적입니다. 성능 resons foreach 루프에 비해이 심지어 최악의 경우
int a;
template <class T>
void print(const T msg)
{
a = msg;
}
// And this is the recursive case:
template <class A, class... B>
void print(A head, B... tail)
{
a = head;
print(head);
print(tail...);
}
그래서 질문이 ....이 [2 목록]에 같은 결과를 실현하려 가능 가능 [3 목록]? 그렇다면, 어떻게?
'fields' 가변 팩, 당신은 이동 포인터 – Manu343726
를 전달하는 유형의 집합이며, (그들이 dessigned하지 않는 방식으로 기능을 사용하는 다형성 (polymorphism)에 대해 대신 배우 : 어떤 경우,이 같은 작업을해야합니다 그리고 전혀 의미가 없습니다.) – Manu343726
필자는 컴파일러가 4-iterations 루프를 풀 것이라고 기대합니다. – jrok