【发布时间】:2014-12-14 00:28:09
【问题描述】:
有如下代码sn-p:
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。
【问题讨论】:
-
typename关键字有什么问题? -
@remyabel,你能举出
typename的例子吗?
标签: c++ c++11 boost metaprogramming template-meta-programming