# std::atomic_flag_test, std::atomic_flag_test_explicit

> C++ Atlas: `cppatlas.com/w/cpp/atomic/atomic_flag_test` | Source: https://en.cppreference.com/w/cpp/atomic/atomic_flag_test | Domain: atomic | Standards: C++20

Atomically reads the value of the *object and returns the value.

## Official Specification Summary (cppreference)

```cpp
// Defined in header <atomic>

bool atomic_flag_test( const volatile std::atomic_flag* object ) noexcept; // (1) (since C++20)

bool atomic_flag_test( const std::atomic_flag* object ) noexcept; // (2) (since C++20)

bool atomic_flag_test_explicit( const volatile std::atomic_flag* object,
                                std::memory_order order ) noexcept; // (3) (since C++20)

bool atomic_flag_test_explicit( const std::atomic_flag* object,
                                std::memory_order order ) noexcept; // (4) (since C++20)
```

Atomically reads the value of the `*object` and returns the value.

1,2) The memory synchronization order is `std::memory_order_seq_cst`.

3,4) The memory synchronization order is `order`.

If `order` is one of `std::memory_order::release` and `std::memory_order::acq_rel`, the behavior is undefined.

### Parameters

- `object` - pointer to the `atomic_flag` object to read
- `order` - the memory synchronization ordering

### Return value

The value atomically read.

### Notes

| Feature-test macro | Value | Std | Feature |
| --- | --- | --- | --- |
| `__cpp_lib_atomic_flag_test` | `201907L` | (C++20) | `std::atomic_flag::test` |

### Example

> Note: This section is incomplete Reason: no example

### See also

- [`test`](https://en.cppreference.com/w/cpp/atomic/atomic_flag/test) (C++20): atomically returns the value of the flag (public member function of `std::atomic_flag`)

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