Skip to content

filtsin/auto_dynamic_cast

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multiple dynamic_cast

Instead of this

auto *first = dynamic_cast<derived1*>(base);
if (first) {
  first->do_smth();
} else {
  auto *second = dynamic_cast<derived2*>(base);
  if (second) {
    second->do_smth();
  } else {
    ...
  }
}

you could write this

auto [first, second] = auto_dynamic_cast<derived1*, derived2*>(base);

if (first) {
  first->do_smth();
} else if (second) {
  second->do_smth();
}

if the required type was found auto_dynamic_cast stops casting next.

For test just include

#include <auto_dynamic_cast.hpp>

About

Multiple dynamic_cast

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages