vxl_platform_tests.cxx
来自「DTMK软件开发包,此为开源软件,是一款很好的医学图像开发资源.」· CXX 代码 · 共 1,194 行 · 第 1/2 页
CXX
1,194 行
//-------------------------------------
#ifdef VCL_HAS_BOOL
void function(int i, void *ptr, bool v) {}
int main() { return 0; }
#endif // VCL_HAS_BOOL
//-------------------------------------
#ifdef VCL_HAS_TYPENAME
template <typename T>
class bingo { public: void bongo(T **); };
int main() { return 0; }
#endif // VCL_HAS_TYPENAME
//-------------------------------------
#ifdef VCL_HAS_EXPORT
export
template <class T, int N>
struct plither
{
plither(){}
~plither(){}
void f(T *, int){}
};
void g()
{
double x;
int y;
plither<double, 3> obj;
obj.f(&x, y);
}
int main() { return 0; }
#endif // VCL_HAS_EXPORT
//-------------------------------------
#ifdef VCL_HAS_MUTABLE
class X {
public:
mutable int const *p;
};
int main() { return 0; }
#endif // VCL_HAS_MUTABLE
//-------------------------------------
#ifdef VCL_HAS_EXPLICIT
class X { public: explicit X(int) {} };
int main() { return 0; }
#endif // VCL_HAS_EXPLICIT
//-------------------------------------
#ifdef VCL_HAS_DYNAMIC_CAST
struct foo { foo(){} virtual ~foo(){} virtual void f()=0; };
struct boo : public foo { void f() { *(int*)0 = 1; } };
boo *try_dynamic_cast() { boo *b = 0; foo *f = b; return dynamic_cast<boo*>(f); }
int main() { return 0; }
#endif // VCL_HAS_DYNAMIC_CAST
//-------------------------------------
#ifdef VCL_HAS_RTTI
#include <typeinfo>
class A { public: virtual ~A() {} virtual void f() {} };
class B : public A { public: void f() {} };
bool try_rtti() { B*b=0; A*a1=b,*a2=b; return typeid(a1)==typeid(a2); }
int main() { return 0; }
#endif // VCL_HAS_RTTI
//-------------------------------------
#ifdef VCL_FOR_SCOPE_HACK
// VCL_FOR_SCOPE_HACK will be set to "1" if this fails to compile
class A { public: void f() { } };
void fn() {
for (int i=0; i<100; ++i) {}
for (long i=0; i<1000; ++i) {}
for (double i = 3.141; i<100.0; i += 1.0) { }
// VC7 only raises warnings for previous tests
A i; i.f();
}
int main() { return 0; }
#endif // VCL_FOR_SCOPE_HACK
//-------------------------------------
#ifdef VCL_DEFAULT_VALUE
// VCL_DEFAULT_VALUE(x) will be set to "= x" if this test fails, to "" otherwise
// declaration
void function(int x, char *ptr = "foo");
// definition
void function(int x, char *ptr) { ++ ptr[x]; }
int main() { return 0; }
#endif // VCL_DEFAULT_VALUE
//-------------------------------------
#ifdef VCL_HAS_MEMBER_TEMPLATES
template <class S>
class blip {
public:
S *ptr;
template <class T> void klor(T *p) { *ptr = *p; }
};
void function()
{
blip<double> b;
int s;
b.klor(&s);
}
int main() { return 0; }
#endif // VCL_HAS_MEMBER_TEMPLATES
//-------------------------------------
#ifdef VCL_CAN_DO_PARTIAL_SPECIALIZATION
template <class T>
class victor
{
T data[256];
public:
victor() {}
T &operator[](unsigned i) { return data[i]; }
};
template <class T>
class victor<T *>
{
T *data[256];
public:
T * &operator[](unsigned i) { return data[i]; }
void slarf() { data[0] += (data[2] - data[1]); }
};
template <class A, class R>
struct foo {
typedef A a;
typedef R r;
};
template <class T> struct foo<T *, T *> { void bar() {} };
template <class T> struct foo<int *, T> { void baz() {} };
int main() { return 0; }
#endif // VCL_CAN_DO_PARTIAL_SPECIALIZATION
//-------------------------------------
#ifdef VCL_DEFINE_SPECIALIZATION
// VCL_DEFINE_SPECIALIZATION is set to "template <>" if this compiles, to "" otherwise
// declaration
template <class T> class traits {};
// specialization
template <>
class traits<double> {
public:
typedef double abs_t;
typedef double float_t;
};
int main() { return 0; }
#endif // VCL_DEFINE_SPECIALIZATION
//-------------------------------------
#ifdef VCL_ALLOWS_INLINE_INSTANTIATION
template <class T>
inline
T dot(T const *a, T const *b)
{
return a[0]*b[0];
}
template double dot(double const *, double const *);
int main() { return 0; }
#endif // VCL_ALLOWS_INLINE_INSTANTIATION
//-------------------------------------
#ifdef VCL_NEEDS_INLINE_INSTANTIATION
// VCL_NEEDS_INLINE_INSTANTIATION is set to 1 if this fails to compile
template <class T>
inline T dot(T const *a, T const *b) { return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]; }
int function();
int call_this() { function(); return 0; }
int function()
{
double a[3] = {1.0, 2.0, 3.0};
double b[3] = {4.0, 5.0, 6.0};
double a_b = dot(a, b);
return int(a_b);
}
// If the program links, the compiler inlined the function template.
int main() { return 0; }
#endif // VCL_NEEDS_INLINE_INSTANTIATION
//-------------------------------------
#ifdef VCL_STATIC_CONST_INIT_INT
class A {
public:
static const int x = 27;
static const bool y = false;
};
int main() { return A::x == 27 && !A::y ? 0 : 1; }
#endif // VCL_STATIC_CONST_INIT_INT
//-------------------------------------
#ifdef VCL_STATIC_CONST_INIT_NO_DEFN
// This should not compile. C++ requires storage to be allocated for
// the constant to use it at runtime. Some compilers do compile this,
// though, and if a definition is given, it becomes a multiply defined
// symbol. If this does compile, we should not give a definition for
// such constants.
class A
{
public:
static const int x = 27;
};
int f(const void* x) { return x?1:0; }
int main() { return f(&A::x); }
#endif // VCL_STATIC_CONST_INIT_NO_DEFN
//-------------------------------------
#ifdef VCL_STATIC_CONST_INIT_FLOAT
class A {
public:
static const float x = 27.0f;
static const double y = 27.0;
};
int main() { return A::x == 27.0f && A::y == 27.0 ? 0 : 1; }
#endif // VCL_STATIC_CONST_INIT_FLOAT
//-------------------------------------
#ifdef VCL_CAN_DO_STATIC_TEMPLATE_MEMBER
template <class T> struct A { A() {} static char *fmt; };
template <class T> char *A<T>::fmt = 0;
int main() { return 0; }
#endif // VCL_CAN_DO_STATIC_TEMPLATE_MEMBER
//-------------------------------------
#ifdef VCL_CAN_DO_NON_TYPE_FUNCTION_TEMPLATE_PARAMETER
template <class T, int n> struct splek { T data[n]; };
template <class T, int n>
void splok_that_splek(splek<T, n> &s)
{
for (int i=0; i<n; ++i)
s.data[i] = T(27);
}
template struct splek<double, 3>;
template void splok_that_splek(splek<double, 3> &);
int main() { return 0; }
#endif // VCL_CAN_DO_NON_TYPE_FUNCTION_TEMPLATE_PARAMETER
//-------------------------------------
#ifdef VCL_NEED_FRIEND_FOR_TEMPLATE_OVERLOAD
// VCL_NEED_FRIEND_FOR_TEMPLATE_OVERLOAD is set to 1 if this fails to compile
template <class T>
class victor_base {
public:
T &operator[](unsigned i) { return data[i]; }
protected:
victor_base(T *p, unsigned n) : data(p), size(n) {}
private:
T *data;
unsigned size;
};
template <class T>
bool operator==(victor_base<T> const&, victor_base<T> const&) { return false; }
template <class T, int n>
class victor_fixed : public victor_base<T> {
public:
T data_fixed[n];
victor_fixed() : victor_base<T>(data_fixed, n) {}
};
int function(victor_fixed<double, 3> const &a,
victor_fixed<double, 3> const &b)
{
if (a == b) // 2.7 fails to resolve this.
return 3141;
else
return 2718;
}
int main() { return 0; }
#endif // VCL_NEED_FRIEND_FOR_TEMPLATE_OVERLOAD
//-------------------------------------
#ifdef VCL_OVERLOAD_CAST
// VCL_OVERLOAD_CAST(x) is set to "(x)" if this compiles, to "((T)(x))" otherwise
template <class T>
class vnl_vector {
public:
unsigned size;
T *data;
vnl_vector(unsigned n, T *ptr) : size(n), data(ptr) {}
};
template <class T>
bool operator==(vnl_vector<T> const&, vnl_vector<T> const&) { return false; }
//
template <unsigned n, class T>
class vnl_vector_fixed : public vnl_vector<T> {
public:
T data_fixedn;
vnl_vector_fixed() : vnl_vector<T>(n, data_fixed) {}
};
//
void print_it(vnl_vector<double> const &){}
void try_it(vnl_vector_fixed<3, double> const &u,
vnl_vector_fixed<3, double> const &v)
{
// gcc 2.7 fails in this function.
if (u == v)
print_it(u);
else {
print_it(u);
print_it(v);
}
}
//
template <class S, class T>
void copy_image(S const * const *src, T * const *dst, int, int) {}
typedef unsigned char byte;
void do_vision(int w, int h, byte **image_i, float **image_f) {
// SGI CC 7.21 fails here.
copy_image(image_i, image_f, w, h);
}
int main() { return 0; }
#endif // VCL_OVERLOAD_CAST
//-------------------------------------
#ifdef VCL_NULL_TMPL_ARGS
// VCL_NULL_TMPL_ARGS is set to "<>" if this fails to compile, to "" otherwise
template <class T> class victor;
template <class T> T dot(victor<T> const &u, victor<T> const &v);
template <class T> class victor {
public:
// Without -fguiding-decls, egcs and 2.95 will rightly think
// this declares a non-template and so the program will fail
// due to access violation below (and missing symbols at link time).
friend T dot(victor<T> const &, victor<T> const &);
private:
T data[3];
};
template <class T> T dot(victor<T> const &u, victor<T> const &v)
{
return // access violation here:
u.data[0] * v.data[0] +
u.data[1] * v.data[1] +
u.data[2] * v.data[2];
}
template double dot(victor<double> const &, victor<double> const &);
double function(victor<double> const &u,
victor<double> const &v)
{
double uu = dot(u, u);
double uv = dot(u, v);
double vv = dot(v, v);
return (uv*uv)/(uu*vv);
}
int main() { return 0; }
#endif // VCL_NULL_TMPL_ARGS
//-------------------------------------
#ifdef VCL_NO_STATIC_DATA_MEMBERS
// VCL_NO_STATIC_DATA_MEMBERS is set to 1 if this fails to compile
template <class T> class vvv { static T xxx; };
template class vvv<int>;
int main() { return 0; }
#endif // VCL_NO_STATIC_DATA_MEMBERS
//-------------------------------------
#ifdef VCL_HAS_TEMPLATE_SYMBOLS
// VCL_HAS_TEMPLATE_SYMBOLS is set to 1 if this fails to link
// Declare a function template.
template <class T> void function(T *ptr, int n);
int caller()
{
double array[3];
function(array, 0); // This should call function<double>(double *, int);
return 0;
}
// Define a non-template function with the same name and signature.
void function(double *, int) {}
// If the program links, the compiler didn't make a distinction.
int main() { return 0; }
#endif // VCL_HAS_TEMPLATE_SYMBOLS
//-------------------------------------
#ifdef VCL_CAN_DO_IMPLICIT_TEMPLATES
# ifdef _MSC_VER
// Use template typing to figure out correct method, because
// several MSVC versions can't cope with overloaded return types
template <class S> struct ims_what;
template <>
struct ims_what<double *> {
typedef double type; };
template <class S>
struct ims_what {
typedef int type; };
template <class I, class T>
void fsm_plop(I b, I e, T x, int)
{
for (I p=b; p!=e; ++p)
*p = x;
}
template <class T>
void fsm_plop(double *b, double *e, T x, double)
{
for (double *p=b; p<e; ++p)
*p = x;
}
template <class I, class T>
inline void fsm_plip(I b, I e, T x)
{
if (b != e)
fsm_plop(b, e, x, ims_what<I>::type());
}
# else
// FSM: The code is imitating the way the gcc STL chooses (or did choose, way
// back) between algorithms for different iterator types. A very brief look
// at the 3.2.2 <algorithm> header suggests they no longer use that mechanism
// so maybe it was deemed non-standard and abandoned.
struct fsm_plap_normal {};
template <class I>
inline fsm_plap_normal fsm_plap(I) { return fsm_plap_normal(); }
struct fsm_plap_double_star {};
inline fsm_plap_double_star fsm_plap(double *) { return fsm_plap_double_star(); }
template <class I, class T>
void fsm_plop(I b, I e, T x, fsm_plap_normal)
{
for (I p=b; p!=e; ++p)
*p = x;
}
template <class T>
void fsm_plop(double *b, double *e, T x, fsm_plap_double_star)
{
for (double *p=b; p<e; ++p)
*p = x;
}
template <class I, class T>
inline void fsm_plip(I b, I e, T x)
{
if (b != e)
fsm_plop(b, e, x, fsm_plap(b));
}
# endif
void f()
{
int iarray[20];
fsm_plip(iarray, iarray+20, 3141);
double darray[20];
fsm_plip(darray, darray+20, 2718);
}
int main() { return 0; }
#endif // VCL_CAN_DO_IMPLICIT_TEMPLATES
//-------------------------------------
#ifdef VCL_CAN_DO_COMPLETE_DEFAULT_TYPE_PARAMETER
template <class T> struct less {};
template <class T, class C=less<int> >
struct X
{
typedef X<T,C> self;
self foo(self const & t) {
if ( t.a == 0 )
return *this;
else
return t;
}
private:
int a;
};
X<int> a;
X<int, less<short> > b;
int main() { return 0; }
#endif // VCL_CAN_DO_COMPLETE_DEFAULT_TYPE_PARAMETER
//-------------------------------------
#ifdef VCL_CAN_DO_TEMPLATE_DEFAULT_TYPE_PARAMETER
template <class T> struct less {};
template <class T, class C=less<T> > struct X { C t1; };
X<int> a;
X<int, less<short> > b;
int main() { return 0; }
#endif // VCL_CAN_DO_TEMPLATE_DEFAULT_TYPE_PARAMETER
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?