tuple의 각 요소의 값을 루프를 통해 값을 가져올 방법이 없을까요?
글쓴이: dltkddyd / 작성시간: 수, 2013/11/20 - 1:42오후
tuple 자료형은 값을 get 전역함수로 가져오던데요. 이건 루프 돌려서 값을 읽어오기 위한 용도로 사용될 수는 없네요. 루프를 돌릴 방법이 없을까요? 코드는 다음과 같습니다.
#include <tuple> #include <iostream> using namespace std; #inclde <memory> tuple<string,string,string,string,string,string> tuple4("single","couple","apple","pear","force","owner"); shared_ptr<decltype(tuple4)> shared5; shared5=make_shared<decltype(tuple4)>(tuple4); cout<<tuple_size<decltype(tuple4)>::value<<endl; for(int i=0;i<tuple_size<decltype(tuple4)>::value;i++) { cout<<get<i>(*shared5);//이 부분에서 문제가 발생합니다. }
get(*shared5)에서 템플릿 인수로 넘어가는 저 i라는 값이 상수라 값이 넘어가지 못하는 것 같은데요. 루프 돌려 *shared5가 의미하는 tuple4 자료형의 각 요소 single, couple, apple.... 에 접근할 수 없을까요?
Forums:
일반적인 for루프로는 불가능합니다. template
일반적인 for루프로는 불가능합니다. template metaprogramming을 이용한 루프를 만드셔야합니다. 그보다 다 같은 타입인데 왜 굳이 tuple을 쓰시나요?
댓글 달기