@@ -313,6 +313,68 @@ void sqrt(InputIterator begin, InputIterator end, OutputIterator out) {
313313 std::transform (begin, end, out, helpers::sqrt ());
314314}
315315
316+ typedef struct {char a[1 ];} CAN_BE_ONE;
317+ typedef struct {char a[2 ];} CAN_BE_TWO;
318+ typedef struct {char a[3 ];} CAN_BE_THREE;
319+ typedef struct {char a[4 ];} CAN_BE_FOUR;
320+ typedef struct {char a[5 ];} CAN_BE_FIVE;
321+ typedef struct {char a[6 ];} CAN_BE_SIX;
322+ typedef struct {char a[7 ];} CAN_BE_SEVEN;
323+ typedef struct {char a[8 ];} CAN_BE_EIGHT;
324+ typedef struct {char a[9 ];} CAN_BE_NINE;
325+ typedef struct {char a[128 ];} CAN_BE_UNKNOWN;
326+
327+ template < std::size_t I >
328+ struct ctype_helper { };
329+
330+ template <>
331+ struct ctype_helper < sizeof (CAN_BE_ONE) > { typedef char type; };
332+
333+ template <>
334+ struct ctype_helper < sizeof (CAN_BE_TWO) > { typedef short type; };
335+
336+ template <>
337+ struct ctype_helper < sizeof (CAN_BE_THREE) > { typedef int type; };
338+
339+ template <>
340+ struct ctype_helper < sizeof (CAN_BE_FOUR) > { typedef long type; };
341+
342+ template <>
343+ struct ctype_helper < sizeof (CAN_BE_FIVE) > { typedef long long type; };
344+
345+ template <>
346+ struct ctype_helper < sizeof (CAN_BE_SIX) > { typedef float type; };
347+
348+ template <>
349+ struct ctype_helper < sizeof (CAN_BE_SEVEN) > { typedef double type; };
350+
351+ template <>
352+ struct ctype_helper < sizeof (CAN_BE_EIGHT) > { typedef long double type; };
353+
354+ template <>
355+ struct ctype_helper < sizeof (CAN_BE_NINE) > { typedef std::string type; };
356+
357+
358+ template < typename T >
359+ struct ctype
360+ {
361+ static CAN_BE_ONE test (const char &);
362+ static CAN_BE_TWO test (const short &);
363+ static CAN_BE_THREE test (const int &);
364+ static CAN_BE_FOUR test (const long &);
365+ static CAN_BE_FIVE test (const long long &);
366+ static CAN_BE_SIX test (const float &);
367+ static CAN_BE_SEVEN test (const double &);
368+ static CAN_BE_EIGHT test (const long double &);
369+ static CAN_BE_NINE test (const std::string &);
370+ static CAN_BE_UNKNOWN test (...);
371+
372+ static T make ();
373+
374+ typedef typename ctype_helper< sizeof (test(make())) >::type type;
375+ };
376+
377+
316378} // namespace algorithm
317379} // namespace Rcpp
318380
0 commit comments