類 any
boost::any — 一個類,其實例可以持有任意滿足ValueType要求的類型的實例。
Synopsis摘要
Description描述
any 構造/複製/析構
-
any();
|
Postconditions: |
this->empty() |
-
any(const any & other);
|
Effects: |
複製構造函數複製
other 的內容到一個新的實例中,因此 any 所含的類型和值都與
other的一樣,如果 other 為空則any也為空。 |
|
Throws: |
可能會拋出一個
std::bad_alloc
異常,或者從所含類型的複製構造函數拋出的任意異常。 |
-
template<typename ValueType> any(const ValueType & value);
|
Effects: |
生成一個 value的拷貝,因此新實例的初始內容的類型和值與
value一致。 |
|
Throws: |
std::bad_alloc
或者其它從所含類型的複製構造函數拋出的異常。 |
-
any & operator=(const any & rhs);
|
Effects: |
將 rhs 的內容複製到當前實例,放棄之前的內容,因此新內容的類型和值與 rhs一致,如果
rhs.empty()則也為空。 |
|
Throws: |
std::bad_alloc
或者其它從所含類型的複製構造函數拋出的異常。賦值操作應滿足強異常安全的保證。 |
-
template<typename ValueType> any & operator=(const ValueType & rhs);
|
Effects: |
生成一個 rhs的拷貝,放棄之前的內容,因此新內容的類型和值與
rhs一致。 |
|
Throws: |
std::bad_alloc
或者其它從所含類型的複製構造函數拋出的異常。賦值操作應滿足強異常安全的保證。 |
-
~any();
|
Effects: |
釋放 any 及所有用於實例管理的資源。 |
|
Throws: |
無 |
any 修改函數
-
any & swap(any & rhs);
|
Effects: |
交換
*this 和
rhs的內容 |
|
Returns: |
*this |
|
Throws: |
無 |
any 查詢函數
-
bool empty() const;
|
Returns: |
true 如果實例為空,否則返回 false. |
|
Throws: |
不會拋出異常。 |
-
const std::type_info & type() const;
|
Returns: |
如果實例非空,則返回所含值的 typeid,否則返回
typeid(void). |
|
Notes: |
用於在編譯期或運行期查詢相應類型。 |