2013-08-21 7 views
1

MPL 코드를 호출하는 메타 함수를 작성할 때 뭔가 빠져있는 것처럼 보입니다. 추적 코드는 INST2에 다음과 같은 오류와 함께 컴파일에 실패하지만, INST1에 잘 작동 :MPL과 비슷한 메타 기능을 어떻게 작성해야합니까?

오류 C2903 : '적용'기호는 클래스 템플릿도 함수 템플릿도

using namespace boost::mpl; 

template <typename VECTOR> 
struct first_element : mpl::at_c<VECTOR, 0> {}; 

int main() 
{ 
    typedef vector< 
     vector<int, int>, 
     vector<int, int>, 
     vector<int, int>> lotso; 

    typedef mpl::transform<lotso, 
     first_element<_1>>::type inst1; 

    typedef first_element< 
     at_c<lotso,0>>::type inst2; 

    return 0; 
} 
+0

템플릿 인스턴스화 백 트랙을 포함한 전체 오류 메시지를 표시 할 수 있습니까? – Pete

답변

1

나는 당신을 생각한다 inst2에 대한 typedef 내에 at_c에 대한 호출 뒤에 ::type을 잊어 버렸습니다. first_elementat_c이 적용될 수있는 것을 기대합니다. 그러나 원시 at_c<lotso, 0>은 아직 평가되지 않았습니다. 메타 기능을 평가하려면 ::type을 추가하십시오.

#include <boost/mpl/vector.hpp> 
#include <boost/mpl/at.hpp> 
#include <boost/mpl/transform.hpp> 
#include <boost/mpl/placeholders.hpp> 
#include <type_traits> 

using namespace boost; 
using namespace boost::mpl; 

template <typename VECTOR> 
struct first_element : mpl::at_c<VECTOR, 0> {}; 

int main() 
{ 
    typedef vector< 
     vector<int, int>, 
     vector<int, int>, 
     vector<int, int>> lotso; 

    typedef mpl::transform<lotso, 
     first_element<_1>>::type inst1; 

    typedef first_element< 
     at_c<lotso,0>::type >::type inst2; 
        ^^^^^^ <--- you forgot a ::type here 

    static_assert(std::is_same<first_element<inst1>::type, inst2>::value, "bingo"); 

    return 0; 
} 

Live Example. 추가 확인으로 inst1에 대한 추가 참조가 inst2과 동일한 유형임을 확인했습니다.