<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ## Operators ### 頭文件: `"boost/operators.hpp"` Operators庫由多個基類組成。每一個類生成與其名字概念相關的操作符。你可以用繼承的方式來 使用它們,如果你需要一個以上的功能,則需要使用多重繼承。幸運的是,Operators中定義了一些復合的概念,在大多數情況下可以無須使用多重繼承。 下面將介紹最常用的一些Operator類,包括它們所表示的概念,以及它們對派生類的要求。某些情況下,使用Operators時,對真實概念的要求會 不同于對該概念基類的要求。例如,概念 addable 要求有一個操作符 `T operator+(const T& lhs,const T& rhs)` 的定義,而Operators的基類 `addable` 卻要求有一個成員函數,`T operator+=(const T& other)`. 使用這個成員函數,基類 `addable` 為派生類自動增加了 `operator+`. 在以下章節中,都是首先給出概念,然后再給出對派生自該概念的類的要求。我沒有重復本庫中的所有概念,僅是挑選了最重要的一些;你可以在 [www.boost.org](http://www.boost.org) 上找到完整的參考文檔。 #### less_than_comparable `less_than_comparable` 要求類型`T`具有以下語義。 ``` bool operator<(const T&,const T&); bool operator>(const T&,const T&); bool operator<=(const T&,const T&); bool operator>=(const T&,const T&); ``` 要派生自 `boost::less_than_comparable`, 派生類(`T`)必須提供: ``` bool operator<(const T&, const T&); ``` 注意,返回值的類型不必是真正的 `bool`, 但必須可以隱式轉換為 `bool`.?C++標準中的概念 LessThanComparable 要求提供`operator&lt;` ,所以從 `less_than_comparable` 派生的類必須符合該要求。作為回報,`less_than_comparable` 將依照 `operator&lt;` 實現其余的三個操作符。 #### equality_comparable `equality_comparable`?要求類型`T`具有以下語義。 ``` bool operator==(const T&,const T&); bool operator!=(const T&,const T&); ``` 要派生自?`boost::equality_comparable`,?派生類(`T`)必須提供: ``` bool operator==(const T&,const T&); ``` 同樣,返回值的類型不必是 `bool`, 但必須可以隱式轉換為 `bool`. C++標準中的概念 EqualityComparable 要求必須提供 `operator==` ,因此從 `equality_comparable` 派生的類必須符合該要求。`equality_comparable` 類為 `T` 提供 `bool operator!=(const T&,const T&)`. #### addable `addable` 概念要求類型`T`具有以下語義。 ``` T operator+(const T&,const T&); T operator+=(const T&); ``` 要派生自 `boost::addable`,?派生類(`T`)必須提供: ``` T operator+=(const T&); ``` 返回值的類型必須可以隱式轉換為 `T`. 類 `addable` 為 `T` 實現 `T operator+(const T&,const T&)`. #### subtractable `subtractable`?概念要求類型`T`具有以下語義。 ``` T operator-(const T&,const T&); T operator-=(const T&); // 譯注:原文為 T operator+=(const T&); 有誤 ``` 要派生自 `boost::subtractable`,?派生類(`T`)必須提供: ``` T operator-=(const T&,const T&); ``` 返回值的類型必須可以隱式轉換為 `T`. 類 `addable` 為 `T` 實現 `T operator-(const T&,const T&)`. #### orable `orable`?概念要求類型`T`具有以下語義。 ``` T operator|(const T&,const T&); T operator|=(const T&,const T&); ``` 要派生自?`boost::orable`,?派生類(`T`)必須提供: ``` T operator|=(const T&,const T&); ``` 返回值的類型必須可以隱式轉換為 `T`. 類 `addable` 為 `T` 實現?`T operator|(const T&,const T&)`. #### andable `andable`?概念要求類型`T`具有以下語義。 ``` T operator&(const T&,const T&); T operator&=(const T&,const T&); ``` 要派生自?`boost::andable`,?派生類(`T`)必須提供: ``` T operator&=(const T&,const T&); ``` 返回值的類型必須可以隱式轉換為 `T`. 類 `addable` 為 `T` 實現?`T operator&(const T&,const T&)`. #### incrementable `incrementable`?概念要求類型`T`具有以下語義。 ``` T& operator++(T&); T operator++(T&,int); ``` 要派生自?`boost::incrementable`,?派生類(`T`)必須提供: ``` T& operator++(T&); ``` 返回值的類型必須可以隱式轉換為 `T`. 類 `addable` 為 `T` 實現?`T operator++(T&,int)`. #### decrementable `decrementable`?概念要求類型`T`具有以下語義。 ``` T& operator--(T&); T operator--(T&,int); ``` 要派生自?`boost::decrementable`,?派生類(`T`)必須提供: ``` T& operator--(T&); ``` 返回值的類型必須可以隱式轉換為 `T`. 類 `addable` 為 `T` 實現?`T operator--(T&,int)`. #### equivalent `equivalent`?概念要求類型`T`具有以下語義。 ``` bool operator<(const T&,const T&); bool operator==(const T&,const T&); ``` 要派生自?`boost::equivalent`,?派生類(`T`)必須提供: ``` bool operator<(const T&,const T&); ``` 返回值的類型必須可以隱式轉換為?`bool`. 類 `equivalent` 為 `T` 實現 `T operator==(const T&,const T&)`. 注意,等價(equivalence)和相等(equality)準確的說是不一樣的;兩個等價(equivalent)的對象并不一定是相等的(equal)。但對于這里的 `equivalent` 概念而言,它們是一樣的。 ### 解引用操作符 對于迭代器,有兩個概念特別有用,`dereferenceable` 和 `indexable`, 分別表示了解引用的兩種情況:一個是`*t`,?`t`是一個支持解引用的迭代器(顯然所有迭代器都支持),另一個是indexing, `t[x]`,?`t`是一個支持下標操作符尋址的類型,而 `x` ?通常是一個整數類型。在更高的抽象級別,它們兩個通常一起使用,合稱迭代器操作符,包括這兩個解引用操作符和一些簡單的算術操作符。 #### dereferenceable `dereferenceable`?概念要求類型`T`具有以下語義,假設 `T` 是操作數,`R` 是引用類型,而 `P` 是指針類型(例如,`T` 是一個迭代器類型,`R` 是該迭代器的`value_type`的引用,而 `P` 則是該迭代器的`value_type`的指針)。 ``` P operator->() const; R operator*() const; ``` 要派生自 `boost::dereferenceable`,?派生類(`T`)必須提供: ``` R operator*() const; ``` 另外,`R`的一元 `operator&` 必須可以被隱式轉換為 `P`. 這意味著 `R` 不必一定要是引用類型,它可以是一個代理類(proxy class)。類`dereferenceable`?為 `T` 實現 `P operator-&gt;() const`. #### indexable `indexable` 概念要求類型`T`具有以下語義,假設 `T` 是操作數,`R` 是引用類型,`P` 是指針類型,而 `D` 是 `difference_type` (例如,`T` 是一個迭代器類型,`R` 是該迭代器的`value_type`的引用,`P`?是該迭代器的`value_type`的指針,而 `D` 則是 `difference_type`)。 ``` R operator[](D) const; R operator+(const T&,D); ``` 要派生自?`boost::indexable`,?派生類(`T`)必須提供: ``` R operator+(const T&,D); ``` 類 `indexable` 為 `T` 實現 `R operator[](D) const`. ### 復合算術操作符 到目前為止我們看到的概念都只代表了最簡單的功能。但是,還有一些高級的,或是復合的概念,它們由幾個簡單概念組合而成,或是在復合概念之上再增加簡單的概念而成。例如,一個類是 `totally_ordered` 的,如果它同時是 `less_than_comparable` 的和 `equality_comparable`的。這些組合很有用,因為它們減少了代碼的數量,同時還表明了重要且常用的概念。由于它們只是表示了已有概念的組合,所以這些概念很容易用一個表格來表示它們所包含的簡單概念。例如,如果一個類派生自 `totally_ordered`, 它必須實現 `less_than_comparable` 所要求的操作符(`bool operator&lt;(const T&,const T&)`) 和 `equality_comparable` 所要求的操作符(`bool operator==(const T&,const T&)`)。 | 組合概念 | 由以下概念組成 | | --- | --- | | totally_ordered | less_than_comparableequality_comparable | | additive | addablesubtractable | | multiplicative | multipliabledividable | | integer_multiplicative | multiplicativemodable | | arithmetic | additivemultiplicative | | integer_arithmetic | additiveinteger_multiplicative | | bitwise | andableorablexorable | | unit_steppable | incrementabledecrementable | | shiftable | left_shiftableright_shiftable | | ring_operators | additivemultipliable | | ordered_ring_operators | ring_operatorstotally_ordered | | field_operators | ring_operatorsdividable | | ordered_field_operators | field_operatorstotally_ordered | | euclidian_ring_operators | ring_operatorsdividablemodable | | ordered_ euclidian_ring_operators | euclidean_ring_operatorstotally_ordered |
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看