Overload of down_cast for references. Use like this: absl::down_cast<T&>(foo). The code is slightly convoluted because we're still using the pointer form of dynamic cast. (The reference form throws an exception if it fails.)

Synopsis

Declared in <absl/base/casts.h>

template<
    typename To,
    typename From>
[[nodiscard]]
To
down_cast(From& f);

Description

There's no need for a special const overload either for the pointer or the reference form. If you call down_cast with a const T&, the compiler will just bind From to const T.

Return Value

f, downcast to To.

Note

The return value should not be discarded.

Parameters

Name

Description

f

The source reference to downcast.

Created with MrDocs