G
Gianni Mariani
I'm trying to make a generic factory that provides a placement new as
well as the accompanying destructor. To do a down-cast I used a
static_cast but it turns out that this is not always a possible because
of virtual inheritance. What I'd like to do is provide an automatic way
of deciding to use a dynamic or static cast depending on if it's
possible to static_cast.
The jist of what I want to do is below but I know it's wrong.
Any ideas ?
template <typename w_to, typename w_from, bool w_is_not = false>
struct is_static_castable
{
enum {
IsStaticCastable = 0
};
};
template <typename w_to, typename w_from>
struct is_static_castable<w_to, w_from, false>
{
enum {
IsStaticCastable = 0 < (int) static_cast< w_to >( (w_from) 0 )
};
};
struct Interface
{
int x;
};
struct Impl
: virtual Interface
{
int Impl;
};
#include <iostream>
int main()
{
std::cout << is_static_castable<Impl *, Interface
*>::IsStaticCastable << "\n";
}
well as the accompanying destructor. To do a down-cast I used a
static_cast but it turns out that this is not always a possible because
of virtual inheritance. What I'd like to do is provide an automatic way
of deciding to use a dynamic or static cast depending on if it's
possible to static_cast.
The jist of what I want to do is below but I know it's wrong.
Any ideas ?
template <typename w_to, typename w_from, bool w_is_not = false>
struct is_static_castable
{
enum {
IsStaticCastable = 0
};
};
template <typename w_to, typename w_from>
struct is_static_castable<w_to, w_from, false>
{
enum {
IsStaticCastable = 0 < (int) static_cast< w_to >( (w_from) 0 )
};
};
struct Interface
{
int x;
};
struct Impl
: virtual Interface
{
int Impl;
};
#include <iostream>
int main()
{
std::cout << is_static_castable<Impl *, Interface
*>::IsStaticCastable << "\n";
}