Boost C++ 库

...世界上最受推崇、设计最精湛的 C++ 库项目之一。 Herb SutterAndrei Alexandrescu, C++ Coding Standards

函数 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