当前位置: 首页>>代码示例>>C++>>正文


C++ expr::get方法代码示例

本文整理汇总了C++中expr::get方法的典型用法代码示例。如果您正苦于以下问题:C++ expr::get方法的具体用法?C++ expr::get怎么用?C++ expr::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在expr的用法示例。


在下文中一共展示了expr::get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ASSERT

/*!\brief Expand an expression of the form scale * addition
 *
 * Provided \c scale is not a sum, expand the expression
 * <tt>scale * (+ c a1 ...)</tt> into <tt>scale * c + scale * a1 + ...</tt>.
 */
ptr<const sum>
expand_prod_sum( const expr &scale, const sum  &addition )
{
  ASSERT( addition.is_expanded() && ! scale.is_a< sum >() );

  if( scale.is_numerical() )
  { // easy case -> sum::sca does the work
    const number &ns = scale.as_a< numerical >()->get();

    ptr< const sum > ret
      = ns.unit()
      ? &addition
      : sum::sca( ns, addition );

    ret->basic::expand();
    return ret;
  }

  // hard case : distribute term by term

  number coef = 0;

  ptr< const prod > scale_prod = scale.get()->as_prod();

  // addition.size() for nsp * addition
  // + 1 for scale_prod * addition.coef()
  container::ptr_unsafe_vector< const prod > seq ( addition.size() + 1 );

  { // coefficient handling
    const prod* ph = scale_prod.get();

    // cannot be numerical since [scale_prod] isn't
    seq.push_back( prod::handle::sca( ph, addition.coef() ) );
  }
  for(const prod* p : addition)
  {
    ASSERT( p );

    const expr ex = prod::mul( *p, *scale_prod );

    // seams reasonable here
    ASSERT( ! ex.is_a< sum >() );

    if( ex.is_numerical() )
      coef += ex.as_a< numerical >()->get();

    else
      seq.push_back( ex.get()->as_prod() );
  }

  expand_detail::sort( seq.begin(), seq.end() );

  ptr< const sum > ret = sum::from_sorted_prod_range( coef, seq.begin(), seq.end() );
  ret->basic::expand(); // mark expanded
  return ret;
}
开发者ID:cjgillot,项目名称:mycas,代码行数:61,代码来源:prod_sum.cpp

示例2: match

bool basic::match(const expr &e, match_state &mm) const
{
  if( e.is_a< wildcard_ >() )
    return match_wild( *this, *e.as_a< wildcard_ >(), mm );

  if( RTTI_ID( this ) != RTTI_ID( e.get() ) )
    return false;

  return match_same_type( *e.get(), mm );
}
开发者ID:cjgillot,项目名称:mycas,代码行数:10,代码来源:match.cpp

示例3: expr_copy

value expr_copy(const expr &e)
{
  value res = expr_allocate();
  Field( res, 1 ) = RTTI_ID( e.get() );
  expr_construct( res ) expr( e );
  return res;
}
开发者ID:cjgillot,项目名称:mycas,代码行数:7,代码来源:expr_wrap.cpp


注:本文中的expr::get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。