[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Redundant dynamic_cast<>
From: |
Andreas Schallenberg |
Subject: |
Re: Redundant dynamic_cast<> |
Date: |
Thu, 06 Apr 2006 13:22:34 +0200 |
User-agent: |
KNode/0.10.1 |
Thomas Maeder wrote:
> ...
> You could of course write a little function template that
> - invokes dynamic_cast if source and destination types are different
> - produces a compiler error if both types are equal
>
> and use that function template instead of dynamic_cast.
That was a good idea. Now I am using such a template function.
In future I plan to replace all dynamic_cast<>s by such functions:
a) "instance_of<>" for tests, where the result of dynamic_cast<> was
used to test.
b) "assert_cast<>" for real conversions during runtime. This function
will throw an exception if the cast fails.
Thank you!
Andreas