⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 replace_if.rst

📁 C++的一个好库。。。现在很流行
💻 RST
字号:
.. Algorithms/Transformation Algorithms//replace_if |50

replace_if
==========

Synopsis
--------

.. parsed-literal::
    
    template<
          typename Sequence
        , typename Pred
        , typename In = |unspecified|
        >
    struct replace_if
    {
        typedef |unspecified| type;
    };



Description
-----------

Returns a copy of the original sequence where every type that satisfies 
the predicate ``Pred`` has been replaced with ``NewType``. 

|transformation algorithm disclaimer|

Header
------

.. parsed-literal::
    
    #include <boost/mpl/replace_if.hpp>



Model of
--------

|Reversible Algorithm|


Parameters
----------

+---------------+-----------------------------------+-------------------------------+
| Parameter     | Requirement                       | Description                   |
+===============+===================================+===============================+
| ``Sequence``  | |Forward Sequence|                | An original sequence.         |
+---------------+-----------------------------------+-------------------------------+
| ``Pred``      | Unary |Lambda Expression|         | A replacement condition.      |
+---------------+-----------------------------------+-------------------------------+
| ``NewType``   | Any type                          | A type to replace with.       |
+---------------+-----------------------------------+-------------------------------+
| ``In``        | |Inserter|                        | An inserter.                  |
+---------------+-----------------------------------+-------------------------------+


Expression semantics
--------------------

|Semantics disclaimer...| |Reversible Algorithm|.

For any |Forward Sequence| ``s``, an unary |Lambda Expression| ``pred``,
an |Inserter| ``in``, and arbitrary type ``x``:


.. parsed-literal::

    typedef replace_if<s,pred,x,in>::type r; 

:Return type:
    A type.

:Semantics:
    Equivalent to 

    .. parsed-literal::
        
        typedef lambda<pred>::type p;
        typedef transform< s, if_< apply_wrap1<p,_1>,x,_1>, in >::type r; 


Complexity
----------

Linear. Performs exactly ``size<s>::value`` applications of ``pred``, and at most 
``size<s>::value`` insertions.


Example
-------

.. parsed-literal::
    
    typedef vector_c<int,1,4,5,2,7,5,3,5> numbers;
    typedef vector_c<int,1,4,0,2,0,0,3,0> expected;
    typedef replace_if< numbers, greater<_,int_<4> >, int_<0> >::type result;
    
    BOOST_MPL_ASSERT(( equal< result,expected, equal_to<_,_> > ));


See also
--------

|Transformation Algorithms|, |Reversible Algorithm|, |reverse_replace_if|, |replace|, |remove_if|, |transform|

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -