2012-08-26 3 views
0

gcc에서 컴파일되고 실행되는 코드가 있는데 MSVC 2012 RC에서 컴파일되지 않습니다. 이유를 설명 할 수 없으므로 MSVC에 버그가 있거나 코드가 잘못되었습니다. push_backatSome<vect_t>의 구성원이 아닌 것을 boost :: enable_if MSVC

http://liveworkspace.org/code/45d78872a2c7f30192277a81c655b471

MSVC 말한다

#include <boost/mpl/vector.hpp> 
#include <boost/mpl/front.hpp> 
#include <boost/mpl/is_sequence.hpp> 
#include <boost/mpl/size.hpp> 
#include <boost/utility/enable_if.hpp> 
#include <vector> 
#include <iostream> 

namespace mpl = boost::mpl; 

template<typename T, 
typename = void> 
struct Some 
{ 
    typedef std::vector<T> type; 
}; 

template<typename T> 
struct Some<T, typename boost::enable_if_c<mpl::is_sequence<T>::type::value>::type> : 
    public Some<typename mpl::front<T>::type>::type 
{ 
}; 


int main() 
{ 
    typedef mpl::vector<int, double> vect_t; 
    typedef Some<vect_t> vector; 
    vector vect; 
    vect.push_back(1); 
    std::cout << "int: " << vect.at(0) << std::endl; 
} 

.

EDIT.

그것은

#include <boost/mpl/vector.hpp> 
#include <boost/mpl/front.hpp> 
#include <boost/mpl/is_sequence.hpp> 
#include <boost/mpl/size.hpp> 
#include <boost/utility/enable_if.hpp> 
#include <vector> 
#include <iostream> 

namespace mpl = boost::mpl; 

template<typename T, typename = void> 
struct Some 
{ 
    typedef std::vector<T> type; 
}; 

template<typename T> 
struct Some<T, typename boost::enable_if_c<mpl::is_sequence<T>::type::value>::type> : 
    public std::vector<int> 
{ 
}; 


int main() 
{ 
    typedef mpl::vector<int, double> vect_t; 
    typedef Some<vect_t>::type vector; 
    vector vect; 
    vect.push_back(1); 
    std::cout << "int: " << vect.at(0) << std::endl; 
} 

이후 MSVC 2012 년에 벌레처럼 보이는

이 오류를 준다 난 ... 그것은 일반적인 경우가 아닌 특성화를 선택, 그래서하지 push_backintstd::vector<boost::mpl::vector<int, double> >로 할 수

편집하다.

이상한

...하지만 그래서, 난 이유를 설명 할 수

template<typename T> 
struct Some<T, typename std::enable_if<boost::mpl::is_sequence<T>::value>::type> : 
    public std::vector<int> 
{ 
}; 

을 예상대로이 작동하지만, MSVC 2012 수 없습니다 enable_if에서 중첩 된 표현과 함께 작업 (또는 가능 템플릿 매개 변수).

template<typename T> 
struct is_int : public std::integral_constant<bool, false> 
{ 
}; 

template<> 
struct is_int<int> : public std::integral_constant<bool , true> 
{ 
}; 

template<typename T, typename = void> 
struct Some 
{ 
    typedef void type; 
}; 

template<typename T> 
struct Some<T, typename std::enable_if<is_int<T>::type::value>::type> 
{ 
    static_assert(is_int<int>::type::value, "asserted"); 
    typedef T type; 
}; 

int main() 
{ 
    static_assert(is_int<T>::type::value, "ass"); 
    Some<int>::type t = 0; 
} 
+0

내가하는 일에 불법적 인 내용이 보이지 않습니다. VC가 잘못되었을 수도 있습니다. gcc와 clang 모두 해당 코드를 허용합니다. – mfontanini

+0

버그를 MSFT에보고하십시오. 확인을 위해 –

답변

1

은 그래서 아마이 때문에 이벤트가 MSVC 2012 결승전에서 그것을 시도하거나 MSVC 2012 익스프레스 대기 MSVC 2012 RC 버전의 버그, 컴파일하고 성공적으로 MSVC 2010 년 코드를 실행합니다.

+0

주셔서 감사합니다. – ForEveR

관련 문제