命名空间
变体
操作

标准库头文件 <any> (C++17)

来自 cppreference.cn
< cpp‎ | header
 
 
标准库头文件
通用工具
<any> (C++17)
<bitset>
<bit> (C++20)
<charconv> (C++17)
<expected> (C++23)
<format> (C++20)
<functional>
<optional> (C++17)
<tuple> (C++11)
<typeindex> (C++11)
<utility>
<variant> (C++17)
容器
<array> (C++11)
<deque>
<flat_map> (C++23)
<flat_set> (C++23)
<forward_list> (C++11)
<hive> (C++26)
<inplace_vector> (C++26)   
<list>
<map>
<mdspan> (C++23)
<queue>
<set>
<span> (C++20)
<stack>
<unordered_map> (C++11)
<unordered_set> (C++11)
<vector>
迭代器
<iterator>
范围
<generator> (C++23)
<ranges> (C++20)
算法
<algorithm>
<numeric>
字符串
<cctype>
<cstring>
<cuchar> (C++11)
<cwchar>
<cwctype>
<string_view> (C++17)
<string>
文本处理
<clocale>
<codecvt> (C++11/17/26*)
<locale>
<regex> (C++11)
<text_encoding> (C++26)   
数值
<cfenv> (C++11)
<cmath>
<complex>
<linalg> (C++26)
<numbers> (C++20)
<random> (C++11)
<simd> (C++26)
<valarray>
时间
<chrono> (C++11)
<ctime>
C 兼容性
<ccomplex> (C++11/17/20*)
<ciso646> (until C++20)
<cstdalign> (C++11/17/20*)
<cstdbool> (C++11/17/20*)
<ctgmath> (C++11/17/20*)
 

此头文件是通用工具库的一部分。

内容

(C++17)
持有任何CopyConstructible类型的实例的对象
(类) [编辑]
当类型不匹配时,由 any_cast 的值返回形式抛出的异常
(类) [编辑]

函数

特化 std::swap 算法
(函数) [编辑]
(C++17)
创建 any 对象
(函数模板) [编辑]
(C++17)
类型安全的访问所含对象
(函数模板) [编辑]

[编辑] 概要

namespace std {
  // class bad_any_cast
  class bad_any_cast;
 
  // class any
  class any;
 
  // non-member functions
  void swap(any& x, any& y) noexcept;
 
  template<class T, class... Args>
    any make_any(Args&&... args);
  template<class T, class U, class... Args>
    any make_any(initializer_list<U> il, Args&&... args);
 
  template<class T>
    T any_cast(const any& operand);
  template<class T>
    T any_cast(any& operand);
  template<class T>
    T any_cast(any&& operand);
 
  template<class T>
    const T* any_cast(const any* operand) noexcept;
  template<class T>
    T* any_cast(any* operand) noexcept;
}

[编辑] std::bad_any_cast

namespace std {
  class bad_any_cast : public bad_cast {
  public:
    // see [exception] for the specification of the special member functions
    const char* what() const noexcept override;
  };
}

[编辑] std::any

namespace std {
  class any {
  public:
    // construction and destruction
    constexpr any() noexcept;
 
    any(const any& other);
    any(any&& other) noexcept;
 
    template<class T>
      any(T&& value);
 
    template<class T, class... Args>
      explicit any(in_place_type_t<T>, Args&&...);
    template<class T, class U, class... Args>
      explicit any(in_place_type_t<T>, initializer_list<U>, Args&&...);
 
    ~any();
 
    // assignments
    any& operator=(const any& rhs);
    any& operator=(any&& rhs) noexcept;
 
    template<class T>
      any& operator=(T&& rhs);
 
    // modifiers
    template<class T, class... Args>
      decay_t<T>& emplace(Args&&...);
    template<class T, class U, class... Args>
      decay_t<T>& emplace(initializer_list<U>, Args&&...);
    void reset() noexcept;
    void swap(any& rhs) noexcept;
 
    // observers
    bool has_value() const noexcept;
    const type_info& type() const noexcept;
  };
}