absl::GetFlag

Returns the value (of type T) of an absl::Flag<T> instance, by value. Do not construct an absl::Flag<T> directly and call absl::GetFlag(); instead, refer to flag's constructed variable name (e.g. FLAGS_name). Because this function returns by value and not by reference, it is thread-safe, but note that the operation may be expensive; as a result, avoid absl::GetFlag() within any tight loops.

Synopsis

Declared in <absl/flags/flag.h>

template<typename T>
[[nodiscard]]
T
GetFlag(absl::Flag<T> const& flag);

Description

Example:

// FLAGS_count is a Flag of type int int my_count = absl::GetFlag(FLAGS_count);

// FLAGS_firstname is a Flag of type std::string std::string first_name = absl::GetFlag(FLAGS_firstname);

Return Value

The current value of flag.

NOTE

The return value should not be discarded.

Parameters

NameDescription
flagThe flag whose value to retrieve.