Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

類 any

boost::any — 一個類,其實例可以持有任意滿足ValueType要求的類型的實例。

Synopsis摘要

class any {
public:
  // construct/copy/destruct   any();
  any(const any &);
  template<typename ValueType> any(const ValueType &);
  any & operator=(const any &);
  template<typename ValueType> any & operator=(const ValueType &);
  ~any();

  // modifiers   any & swap(any &);

  // queries   bool empty() const;
  const std::type_info & type() const;
};

Description描述

any 構造/複製/析構

  1. any();
    Postconditions: this->empty()
  2. any(const any & other);
    Effects: 複製構造函數複製 other 的內容到一個新的實例中,因此 any 所含的類型和值都與 other的一樣,如果 other 為空則any也為空。
    Throws: 可能會拋出一個 std::bad_alloc 異常,或者從所含類型的複製構造函數拋出的任意異常。
  3. template<typename ValueType> any(const ValueType & value);
    Effects: 生成一個 value的拷貝,因此新實例的初始內容的類型和值與 value一致。
    Throws: std::bad_alloc 或者其它從所含類型的複製構造函數拋出的異常。
  4. any & operator=(const any & rhs);
    Effects: rhs 的內容複製到當前實例,放棄之前的內容,因此新內容的類型和值與 rhs一致,如果 rhs.empty()則也為空。
    Throws: std::bad_alloc 或者其它從所含類型的複製構造函數拋出的異常。賦值操作應滿足強異常安全的保證。
  5. template<typename ValueType> any & operator=(const ValueType & rhs);
    Effects: 生成一個 rhs的拷貝,放棄之前的內容,因此新內容的類型和值與 rhs一致。
    Throws: std::bad_alloc 或者其它從所含類型的複製構造函數拋出的異常。賦值操作應滿足強異常安全的保證。
  6. ~any();
    Effects: 釋放 any 及所有用於實例管理的資源。
    Throws:

any 修改函數

  1. any & swap(any & rhs);
    Effects: 交換 *thisrhs的內容
    Returns: *this
    Throws:

any 查詢函數

  1. bool empty() const;
    Returns: true 如果實例為空,否則返回 false.
    Throws: 不會拋出異常。
  2. const std::type_info & type() const;
    Returns: 如果實例非空,則返回所含值的 typeid,否則返回 typeid(void).
    Notes: 用於在編譯期或運行期查詢相應類型。
Copyright © 2001 Kevlin Henney

PrevUpHomeNext