Unlike isa<> and cast<>, current implementation of dyn_cast<> fails
to process a std::unique_ptr to a class supporting LLVM RTTI:
// A and B support LLVM RTTI
class A {...}
class B: public A {...}
void foo() {
...
auto V = std::make_unique<A>(); auto VB = dyn_cast<B>(std::move(V)); if (VB) ...
...
}
I think you want std::forward<std::unique_ptr<From>>(f)? - see here:
https://en.cppreference.com/w/cpp/utility/forward
For example, if used in a wrapper such as the following, the template behaves as described below: template<class T> void wrapper(T&& arg) { // arg is always lvalue foo(std::forward<T>(arg)); // Forward as lvalue or as rvalue, depending on T } If a call to wrapper() passes an rvalue std::string, then T is deduced to std::string (not std::string&, const std::string&, or std::string&&), and std::forward ensures that an rvalue reference is passed to foo. If a call to wrapper() passes a const lvalue std::string, then T is deduced to const std::string&, and std::forward ensures that a const lvalue reference is passed to foo. If a call to wrapper() passes a non-const lvalue std::string, then T is deduced to std::string&, and std::forward ensures that a non-const lvalue reference is passed to foo.