Boost C++ 库

...世界上最受推崇和设计最精良的 C++ 库项目之一。 Herb SutterAndrei Alexandrescu, C++ 编码规范

函数 polymorphic_get - Boost C++ 函数库
PrevUpHomeNext

函数 polymorphic_get

boost::polymorphic_get — 从给定的 variant 中检索指定类型的值。

提要

// In header: <boost/variant/polymorphic_get.hpp>


template<typename U, typename T1, typename T2, ..., typename TN> 
  U * polymorphic_get(variant<T1, T2, ..., TN> * operand);
template<typename U, typename T1, typename T2, ..., typename TN> 
  const U * polymorphic_get(const variant<T1, T2, ..., TN> * operand);
template<typename U, typename T1, typename T2, ..., typename TN> 
  U & polymorphic_get(variant<T1, T2, ..., TN> & operand);
template<typename U, typename T1, typename T2, ..., typename TN> 
  const U & polymorphic_get(const variant<T1, T2, ..., TN> & operand);

描述

如果未定义 BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT,则等价于 polymorphic_strict_get。 如果定义了 BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT,则等价于 polymorphic_relaxed_get

推荐:在新代码中使用 polymorphic_get,并且不要定义 BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT。 这样,polymorphic_get 提供更多的编译时检查,并且其行为更接近 C++ 标准库中的 std::get


PrevUpHomeNext