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

📄 replace.rst

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

replace
=======

Synopsis
--------

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



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

Returns a copy of the original sequence where every type identical to ``OldType`` 
has been replaced with ``NewType``. 

|transformation algorithm disclaimer|

Header
------

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


Model of
--------

|Reversible Algorithm|


Parameters
----------

+---------------+-----------------------------------+-------------------------------+
| Parameter     | Requirement                       | Description                   |
+===============+===================================+===============================+
| ``Sequence``  | |Forward Sequence|                | A original sequence.          |
+---------------+-----------------------------------+-------------------------------+
| ``OldType``   | Any type                          | A type to be replaced.        |
+---------------+-----------------------------------+-------------------------------+
| ``NewType``   | Any type                          | A type to replace with.       |
+---------------+-----------------------------------+-------------------------------+
| ``In``        | |Inserter|                        | An inserter.                  |
+---------------+-----------------------------------+-------------------------------+


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

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

For any |Forward Sequence| ``s``, an |Inserter| ``in``, and arbitrary types ``x`` and ``y``:


.. parsed-literal::

    typedef replace<s,x,y,in>::type r; 

:Return type:
    A type.
 
:Semantics:
    Equivalent to 

    .. parsed-literal::
    
        typedef replace_if< s,y,is_same<_,x>,in >::type r; 


Complexity
----------

Linear. Performs exactly ``size<s>::value`` comparisons for 
identity / insertions.


Example
-------

.. parsed-literal::
    
    typedef vector<int,float,char,float,float,double> types;
    typedef vector<int,double,char,double,double,double> expected;
    typedef replace< types,float,double >::type result;
    
    BOOST_MPL_ASSERT(( equal< result,expected > ));


See also
--------

|Transformation Algorithms|, |Reversible Algorithm|, |reverse_replace|, |replace_if|, |remove|, |transform|

⌨️ 快捷键说明

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