# std::any::has_value

> C++ Atlas: `cppatlas.com/w/cpp/utility/any/has_value` | Source: https://en.cppreference.com/w/cpp/utility/any/has_value | Domain: Utility | Standards: C++17

Checks whether the object contains a value.

## Official Specification Summary (cppreference)

```cpp
bool has_value() const noexcept; // (since C++17)
```

Checks whether the object contains a value.

### Parameters

(none)

### Return value

`true` if and only if the instance contains a value.

### Example

```cpp
#include <any>
#include <cassert>
#include <string>

int main()
{
    std::any a0;
    assert(a0.has_value() == false);

    std::any a1 = 42;
    assert(a1.has_value() == true);
    assert(std::any_cast<int>(a1) == 42);
    a1.reset();
    assert(a1.has_value() == false);

    auto a2 = std::make_any<std::string>("Andromeda");
    assert(a2.has_value() == true);
    assert(std::any_cast<std::string&>(a2) == "Andromeda");
    a2.reset();
    assert(a2.has_value() == false);
}
```

### See also

- [`reset`](https://en.cppreference.com/w/cpp/utility/any/reset): destroys contained object (public member function)

---
Attribution: content from https://en.cppreference.com/w/cpp/utility/any/has_value (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.