A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://timsong-cpp.github.io/cppwp/n4659/any.nonmembers below:

[any.nonmembers]

23 General utilities library [utilities] 23.8 Storage for any type [any] 23.8.4 Non-member functions [any.nonmembers]

void swap(any& x, any& y) noexcept;

Effects: As if by x.swap(y).

template <class T, class... Args> any make_any(Args&& ...args);

Effects: Equivalent to: return any(in_­place_­type<T>, std​::​forward<Args>(args)...);

template <class T, class U, class... Args> any make_any(initializer_list<U> il, Args&& ...args);

Effects: Equivalent to: return any(in_­place_­type<T>, il, std​::​forward<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);

Let U be the type remove_­cv_­t<remove_­reference_­t<ValueType>>.

Requires: For the first overload, is_­constructible_­v<ValueType, const U&> is true. For the second overload, is_­constructible_­v<ValueType, U&> is true. For the third overload, is_­constructible_­v<ValueType, U> is true. Otherwise the program is ill-formed.

Returns: For the first and second overload, static_­cast<ValueType>(*any_­cast<U>(&operand)). For the third overload, static_­cast<ValueType>(std​::​move(*any_­cast<U>(&operand))).

Throws: bad_­any_­cast if operand.type() != typeid(remove_­reference_­t<T>).

[Example:

any x(5);                                   assert(any_cast<int>(x) == 5);              any_cast<int&>(x) = 10;                     assert(any_cast<int>(x) == 10);

x = "Meow";                                 assert(strcmp(any_cast<const char*>(x), "Meow") == 0);
any_cast<const char*&>(x) = "Harry";
assert(strcmp(any_cast<const char*>(x), "Harry") == 0);

x = string("Meow");                         string s, s2("Jane");
s = move(any_cast<string&>(x));             assert(s == "Meow");
any_cast<string&>(x) = move(s2);            assert(any_cast<const string&>(x) == "Jane");

string cat("Meow");
const any y(cat);                           assert(any_cast<const string&>(y) == cat);

any_cast<string&>(y);                                                                   

end example]

template<class T> const T* any_cast(const any* operand) noexcept; template<class T> T* any_cast(any* operand) noexcept;

Returns: If operand != nullptr && operand->type() == typeid(T), a pointer to the object contained by operand; otherwise, nullptr.

[Example:

bool is_string(const any& operand) {
  return any_cast<string>(&operand) != nullptr;
}

end example]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4