Code: Alles auswählen
class X {
public:
template<class T> X(T&&);
X(const X&);
};
X x(42); // aufruf von X::X(T&&)
X y(x); // aufruf von X::X(T&&) anstatt X::X(const X&)
Code: Alles auswählen
class X {
public:
template<class T> X(T&&);
X(const X&);
};
X x(42); // aufruf von X::X(T&&)
X y(x); // aufruf von X::X(T&&) anstatt X::X(const X&)
Code: Alles auswählen
template<class U> struct D
{
private:
class IsRefl { char c[2]; };
class IsNotRefl { char c[3]; };
static IsRefl checkRefl(Reflectable*);
static IsNotRefl checkRefl(...);
public:
enum { v = ((sizeof(IsRefl) == sizeof(checkRefl(static_cast<Reflectable*>(static_cast<U*>(nullptr))))) ? Flags::Refl : 0), p = 0 };
static_assert(v != 0, "Occurence of type not supported by type system.");
};
template<> struct D<Bool> { enum { v = Flags::Bool, p = 0 }; };
template<> struct D<Char> { enum { v = Flags::Char, p = 0 }; };
template<> struct D<Int1> { enum { v = Flags::Int1, p = 0 }; };
template<> struct D<Int2> { enum { v = Flags::Int2, p = 0 }; };
template<> struct D<Int4> { enum { v = Flags::Int4, p = 0 }; };
template<> struct D<Int8> { enum { v = Flags::Int8, p = 0 }; };
template<> struct D<UInt1> { enum { v = Flags::UInt1, p = 0 }; };
template<> struct D<UInt2> { enum { v = Flags::UInt2, p = 0 }; };
template<> struct D<UInt4> { enum { v = Flags::UInt4, p = 0 }; };
template<> struct D<UInt8> { enum { v = Flags::UInt8, p = 0 }; };
template<> struct D<Float4> { enum { v = Flags::Float4, p = 0 }; };
template<> struct D<Float8> { enum { v = Flags::Float8, p = 0 }; };
template<> struct D<String> { enum { v = Flags::String, p = 0 }; };
template<class U> struct D<U&> { enum { v = Flags::Ref | D<U>::v, p = D<U>::p }; };
template<class U> struct D<U*> { enum { v = (1 << Flags::PtrOffset) + D<U>::v, p = D<U>::p + 1 }; static_assert(p < 7, "More than 6 pointer indirections not supported"); };
template<class U> struct D<const U> { enum { v = 1 << (Flags::ConstOffset + D<U>::p) | D<U>::v, p = D<U>::p }; };
// BEISPIEL
Variant v(42.0);
v.as<String>(); // knallt
Float8 = v.as<Float8>(); // geht