5#define __XTD_STD_INTERNAL__ 
    7#undef __XTD_STD_INTERNAL__ 
    9#if defined(__xtd__cpp_lib_any) 
   17  template <
typename value_t>
 
   18  value_t any_cast(
const any& any);
 
   20  template <
typename value_t>
 
   21  value_t* any_cast(any* any) 
noexcept;
 
   23  template <
typename value_t>
 
   24  const value_t* any_cast(
const any* any) 
noexcept;
 
   26  class bad_any_cast : 
public std::bad_cast {
 
   28    const char* what() const noexcept
 override {
return "bad any cast";}
 
   33    any() noexcept = default;
 
   34    any(const any& other) : content(other.content ? other.content->clone() : 
nullptr) {}
 
   35    template <
typename value_t>
 
   36    any(
const value_t& value) : content(new derived<value_t>(value)) {}
 
   37    template <
typename value_t>
 
   38    any(value_t&& value) : content(new derived<value_t>(std::move(value))) {}
 
   42    any& operator=(
const any& other) {
 
   43      if (
this == &other) 
return *
this;
 
   45      content = 
other.content ? 
other.content->clone() : 
nullptr;
 
   49    any& operator=(
const any&& other) 
noexcept {
 
   50      if (
this == &other) 
return *
this;
 
   52      content = 
other.content ? std::move(
other.content) : nullptr;
 
   56    template <
typename value_t>
 
   57    any& operator=(
const value_t& value) {
 
   59      content = 
new derived<value_t>(value);
 
   63    bool has_value() const noexcept {
return content != 
nullptr;}
 
   65    const std::type_info& 
type() const noexcept {
return content ? content->type : 
typeid(void);}
 
   67    void reset() noexcept {
delete content;}
 
   70    template <
typename value_t>
 
   71    friend value_t any_cast(
const any& any);
 
   73    template <
typename value_t>
 
   74    friend value_t* any_cast(any* any) 
noexcept;
 
   76    template <
typename value_t>
 
   77    friend const value_t* any_cast(
const any* any) 
noexcept;
 
   79    template <
typename value_t>
 
   81      return static_cast<derived<value_t>*
>(content)->data;
 
   84    template <
typename value_t>
 
   85    const value_t& value()
 const {
 
   86      return static_cast<derived<value_t>*
>(content)->data;
 
   90      base(
const type_info& type) : 
type(
type) {}
 
   92      virtual base* clone() 
const = 0;
 
   94      const type_info& 
type;
 
   97    template <
typename value_t>
 
   98    struct derived : 
public base {
 
   99      derived(
const value_t& value) : base(typeid(value)), data(value) {}
 
  102      value_t& operator*() {
return data;}
 
  104      base* clone()
 const override {
 
  105        return new derived<value_t>(*
this);
 
  109    base* content = 
nullptr;
 
  112  template <
typename value_t>
 
  113  value_t any_cast(
const any& any) {
 
  114    if (!
any.has_value() || 
typeid(value_t) != 
any.type()) 
throw bad_any_cast();
 
  115    return any.value<value_t>();
 
  118  template <
typename value_t>
 
  119  value_t* any_cast(any* any) 
noexcept {
 
  120    if (any == 
nullptr || !
any->has_value() || 
typeid(value_t) != 
any->type()) 
return nullptr;
 
  121    return any->value<value_t>();
 
  124  template <
typename value_t>
 
  125  const value_t* any_cast(
const any* any) 
noexcept {
 
  126    if (any == 
nullptr || !
any->has_value() || 
typeid(value_t) != 
any->type()) 
return nullptr;
 
  127    return any->value<value_t>();
 
  130  template <
typename value_t>
 
  131  any make_any(value_t&& value) {
 
  132    return any(std::forward<value_t>(value));
 
Contains __xtd_std_version definitions.
 
std::type_info type
Stores information about a type.
Definition type.hpp:23
 
@ any
Indicates that all styles except allow_binary_specifier, allow_octal_specifier and allow_hex_specifie...
 
@ other
The operating system is other.