Assuming a class template `Optional` exists:

```
template <class T>
class Optional
{
public:
  ...
  bool isPresent(void) const {...}
  const T& value(void) {...} // throws if !isPresent()
  ...
};

```

Also, some structs with nested `Optional` fields are defined:

```
struct A;
struct B;
struct C;
struct D;

struct A
{
   Optional<B> b1_;
   int i_;
};

struct B
{
   Optional<C> c1_;
   int j_;
};

struct C
{
   Optional<D> d1_;
   int k_;
};

struct D
{
   int l_;
   int m_;
   int n_;
};

```

I'm looking for a programming idiom that provides the following behavior without the ugliness.

```
int get_l_OrDefault(const A& a, int def)
{
  if (!a.b_.isPresent()) return def;
  else if (!a.b_.value().c_.isPresent()) return def;
  else if (!a.b_.value().c_.value().d_.isPresent()) return def;
  else return a.b_.value().c_.value().d_.value().l_;
}

```

Given an `A a;`, can I define something that takes some representation of the path to the non-optional leaf field and a default value?

```
getValueOrDefault(a.b.j_, 0);
getValueOrDefault(a.b.c.k_, 0);
... etc

```