3.11.0-rc 3.10.0 (latest) 3.9.0 3.8.0 3.7.0 3.6.0 3.5.0 3.4.0 3.3.0 3.2.0 2.48.0-rc 2.47.1 2.46.0 2.45.0 2.44.0 2.43.0 2.42.0 2.41.0 2.40.0 2.39.0 2.38.0 2.37.0 2.36.0 2.35.0 2.34.0 2.33.0 2.32.0 2.31.0 2.30.0 2.29.0 2.28.0 2.27.0 2.26.0 2.25.1 2.24.0 2.23.0 2.22.1 2.21.0 2.20.0 2.19.0 2.18.0 2.17.0 2.16.0 2.15.1 2.14.0 2.13.0 2.12.0 2.11.0 2.10.1 A class that holds option structs indexed by their type.
An "Option" is any struct that has a public `Type` member typedef. By convention they are named like "FooOption". Each library (e.g., spanner, storage) may define their own set of options. Additionally, there are common options defined that many libraries may use. All these options may be set in a single [`Options`](https://docs.cloud.google.com/cpp/docs/reference/common/latest/classgoogle_1_1cloud_1_1Options) instance, and each library will look at the options that it needs.

Here's an overview of this class's interface, but see the method documentation below for details.

- `.set<T>(x)`-- Sets the option `T` to value `x`
- `.has<T>()`-- Returns true iff option `T` is set
- `.unset<T>()`-- Removes the option `T`
- `.get<T>()`-- Gets a const-ref to the value of option `T`
- `.lookup<T>(x)`-- Gets a non-const-ref to option `T`'s value, initializing it to `x` if it was not set (`x` is optional).

###### Example:

    struct FooOption {
      using Type = int;
    };
    struct BarOption {
      using Type = std::set<std::string>;
    };
    ...
    Options opts;

    assert(opts.get<FooOption>() == 0);
    opts.set<FooOption>(42);
    assert(opts.get<FooOption>() == 42);

    // Inserts two elements directly into the BarOption's std::set.
    opts.lookup<BarOption>().insert("hello");
    opts.lookup<BarOption>().insert("world");

    std::set<std::string> const& bar = opts.get<BarOption>();
    assert(bar == std::set<std::string>{"hello", "world"});

## Constructors

### Options()

Constructs an empty instance.

### Options(Options const \&)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `rhs` | `Options const &` |

### Options(Options \&\&)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `rhs` | `Options &&` |

## Operators

### operator=(Options const \&)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `rhs` | `Options const &` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `Options &` |   |

### operator=(Options \&\&)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `rhs` | `Options &&` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `Options &` |   |

## Functions

### set(ValueTypeT\< T \>) \&

Sets option `T` to the value `v` and returns a reference to `*this`.

    struct FooOption {
      using Type = int;
    };
    auto opts = Options{};
    opts.set<FooOption>(123);

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `v` | `ValueTypeT< T >` the value to set the option T |
| `typename T` | the option type |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `Options &` |   |

### set(ValueTypeT\< T \>) \&\&

Sets option `T` to the value `v` and returns a reference to `*this`.

    struct FooOption {
      using Type = int;
    };
    auto opts = Options{}.set<FooOption>(123);

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `v` | `ValueTypeT< T >` the value to set the option T |
| `typename T` | the option type |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `Options &&` |   |

### has() const

Returns true IFF an option with type `T` exists.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `typename T` | the option type |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `bool` |   |

### unset()

Erases the option specified by the type `T`.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `typename T` | the option type |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `void` |   |

### get() const

Returns a reference to the value for `T`, or a value-initialized default if `T` was not set.
This method will always return a reference to a valid value of the correct type for option `T`, whether or not `T` has actually been set. Use `has<T>()` to check whether or not the option has been set.

    struct FooOption {
      using Type = std::set<std::string>;
    };
    Options opts;
    std::set<std::string> const& x = opts.get<FooOption>();
    assert(x.empty());
    assert(!x.has<FooOption>());

    opts.set<FooOption>({"foo"});
    assert(opts.get<FooOption>().size() == 1);

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `typename T` | the option type |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `ValueTypeT< T > const &` |   |

### lookup(ValueTypeT\< T \>)

Returns a reference to the value for option `T`, setting the value to `init_value` if necessary.

    struct BigOption {
      using Type = std::set<std::string>;
    };
    Options opts;
    std::set<std::string>& x = opts.lookup<BigOption>();
    assert(x.empty());

    x.insert("foo");
    opts.lookup<BigOption>().insert("bar");
    assert(x.size() == 2);

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `value` | `ValueTypeT< T >` the initial value to use if `T` is not set (optional) |
| `typename T` | the option type |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `ValueTypeT< T > &` |   |