2

:부스트없이 BOOST_DEDUCED_TYPENAME의 구현 다음 코드가

template<typename ValueType> 
ValueType any_cast(any & operand) 
{ 
    typedef BOOST_DEDUCED_TYPENAME remove_reference<ValueType>::type nonref; 


    nonref * result = any_cast<nonref>(&operand); 
    if(!result) 
     boost::throw_exception(bad_any_cast()); 

    // Attempt to avoid construction of a temporary object in cases when 
    // `ValueType` is not a reference. Example: 
    // `static_cast<std::string>(*result);` 
    // which is equal to `std::string(*result);` 
    typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_< 
     boost::is_reference<ValueType>, 
     ValueType, 
     BOOST_DEDUCED_TYPENAME boost::add_reference<ValueType>::type 
    >::type ref_type; 

    return static_cast<ref_type>(*result); 
} 

Boost없이 BOOST_DEDUCED_TYPENAME을 구현 가능한 거기가? 나는 C++11 만 사용할 수 있습니다.

+0

'typename' 키워드의 문제점은 무엇입니까? –

+0

@remyabel,이 경우'typename'을 사용하여 어떤 예를들 수 있습니까? – Denis

답변

5

C++ 11 가능 컴파일러를 사용하는 경우 BOOST_DEDUCED_TYPENAME이 필요하지 않을 가능성이 매우 높습니다. 즉, 이것은 include/boost/config/suffix.hpp에 있습니다

// BOOST_DEDUCED_TYPENAME workaround ------------------------------------------// 
// 
// Some compilers don't support the use of `typename' for dependent 
// types in deduced contexts, e.g. 
// 
//  template <class T> void f(T, typename T::type); 
//         ^^^^^^^^ 
// Replace these declarations with: 
// 
//  template <class T> void f(T, BOOST_DEDUCED_TYPENAME T::type); 

#ifndef BOOST_NO_DEDUCED_TYPENAME 
# define BOOST_DEDUCED_TYPENAME typename 
#else 
# define BOOST_DEDUCED_TYPENAME 
#endif 

는 그냥 typename 키워드를 사용합니다.

+0

답장을 보내 주셔서 감사합니다. – Denis