Основываясь на ответе Бенуа, я придумал следующий ответ. Ответ состоит из трех файлов:
MyPointTypes.h
MyPointTypeImpl.h
MyPointTypes.cpp
MyPointTypes.h:
#ifndef __MYSTRUCTURES_H__
#define __MYSTRUCTURES_H__
#include <boost/preprocessor/iteration/iterate.hpp>
#include <boost/preprocessor/seq/size.hpp>
typedef signed char int8;
typedef unsigned char uint8;
typedef signed short int16;
typedef unsigned short uint16;
typedef signed int int32;
typedef unsigned int uint32;
typedef signed int int64;
typedef unsigned int uint64;
typedef float float32;
typedef double float64;
#define MY_SIGNED_INTEGER_SEQ (int8)(int16)(int32)(int64)
#define MY_SIGNED_INTEGER_SUFFIX_SEQ (I8)(I16)(I32)(I64)
#define MY_UNSIGNED_INTEGER_SEQ (uint8)(uint16)(uint32)(uint64)
#define MY_UNSIGNED_INTEGER_SUFFIX_SEQ (UI8)(UI16)(UI32)(UI64)
#define MY_SIGNED_UNSIGNED_INTEGER_SEQ MY_SIGNED_INTEGER_SEQ MY_UNSIGNED_INTEGER_SEQ
#define MY_SIGNED_UNSIGNED_INTEGER_SUFFIX_SEQ MY_SIGNED_INTEGER_SUFFIX_SEQ MY_UNSIGNED_INTEGER_SUFFIX_SEQ
#define MY_FLOAT_SEQ (float32)(float64)
#define MY_FLOAT_SUFFIX_SEQ (F32)(F64)
#define MY_BASIC_NUMERIC_TYPES_SEQ MY_SIGNED_UNSIGNED_INTEGER_SEQ MY_FLOAT_SEQ
#define MY_BASIC_NUMERIC_TYPES_SUFFIX_SEQ MY_SIGNED_UNSIGNED_INTEGER_SUFFIX_SEQ MY_FLOAT_SUFFIX_SEQ
#define MY_SEQ_OF_TYPES MY_BASIC_NUMERIC_TYPES_SEQ
#define MY_SEQ_OF_SUFFICES MY_BASIC_NUMERIC_TYPES_SUFFIX_SEQ
#define BOOST_PP_ITERATION_LIMITS (0, BOOST_PP_SEQ_SIZE(MY_SEQ_OF_TYPES) - 1)
#include BOOST_PP_ITERATE()
#undef MY_SEQ_OF_TYPES
#undef MY_SEQ_OF_SUFFICES
#endif
MyPointTypeImpl.h:
#include <boost/preprocessor/seq/elem.hpp>
#define n BOOST_PP_ITERATION()
#define PASTER(x,y) x ## y
#define EVALUATOR(x,y) PASTER(x,y)
#define CONCATEVALUATED(x, y) EVALUATOR(x, y)
#define TYPE BOOST_PP_SEQ_ELEM(n, MY_SEQ_OF_TYPES)
#define SUFFIX BOOST_PP_SEQ_ELEM(n, MY_SEQ_OF_SUFFICES)
#define ADDSUFFIX(cls) CONCATEVALUATED(cls, SUFFIX)
struct ADDSUFFIX(Point)
{
TYPE X;
TYPE Y;
};
#undef n
MyPointTypes.cpp:
#define BOOST_PP_FILENAME_1 "MyPointTypeImpl.h"
#include "MyPointTypes.h"
Это определит типы:
PointI8, PointI16, PointI32, PointI64,
PointUI8, PointUI16, PointUI32, PointUI64,
PointF32, PointF64
Вообразите тогда вместо структуры C ++ тип значения C ++ / CLI, т.е.
public value class Point
Затем мы эффективно создали точечные типы всех основных числовых типов для использования в .NET, например. C #.