#if defined(_MSC_VER) && _MSC_VER >= 1300 #pragma warning (disable : 4503 4244) #endif // 4503: decorated name length exceeded, name was truncated // 4244: 'argument' : conversion from '' to '', possible loss of data #include #include #include #include "Variant.h" using namespace std; int main() { try { typedef Variant DBField; DBField fld1(string("Hello, world")); DBField fld2(25); DBField fld3(3.14); assert(fld1.TypeId() == typeid(string)); assert(fld2.TypeId() == typeid(int)); string* p = fld1.GetPtr(); assert(p != 0); *p += '!'; assert(fld1.Get() == "Hello, world!"); fld3 = fld1; assert(fld1.Get() == "Hello, world!"); assert(fld3.Get() == "Hello, world!"); fld3 = std::string("Assignment"); assert(fld3.Get() == "Assignment"); DBField fld5; assert(fld5.TypeId() == typeid(string)); assert(fld5.GetPtr()->empty()); DBField fld4 = fld1; assert(fld4.TypeId() == typeid(string)); assert(fld4.Get() == "Hello, world!"); DBField fld(45); float f = fld.ConvertTo(); assert(f == 45); (void)f; fld2.ChangeType(); assert(fld2.Get() == 25); typedef Variant AlternateDBField; AlternateDBField fld6(fld1); assert(fld6.Get() == "Hello, world!"); fld6 = fld3; assert(fld6.Get() == "Assignment"); #if defined(_MSC_VER) && _MSC_VER >= 1300 // // Variant with VC non-standard alignment support // typedef TYPELIST_3(string, double, int) DBField2Typelist; typedef Variant > AlternateDBField2; AlternateDBField2 fld7(fld6); assert(fld7.Get() == "Assignment"); fld7 = fld2; assert(fld7.Get() == 25.0); enum { OrigAlign = __alignof(fld1), VCExAlign = __alignof(fld7) }; STATIC_CHECK(OrigAlign == VCExAlign, WrongAlignment); #endif // def _MSC_VER } catch (const std::exception& e) { cout << "Something weird happened: " << e.what(); } catch (...) { cout << "Something really weird happened."; } }