incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Lemings" <Eric.Lemi...@roguewave.com>
Subject RE: structure of tuple tests ([Fwd: Re: svn commit: r675044 - in /stdcxx/branches/4.3.x: include/rw/_tuple.h include/tuple tests/utilities/20.tuple.cnstr.cpp tests/utilities/20.tuple.creation.cpp tests/utilities/20.tuple.h tests/utilities/20.tuple.helpers
Date Thu, 17 Jul 2008 14:51:41 GMT
 

> -----Original Message-----
> From: Martin Sebor [mailto:msebor@gmail.com] On Behalf Of Martin Sebor
> Sent: Wednesday, July 16, 2008 11:15 PM
> To: dev@stdcxx.apache.org
> Subject: Re: structure of tuple tests ([Fwd: Re: svn commit: 
> r675044 - in /stdcxx/branches/4.3.x: include/rw/_tuple.h 
> include/tuple tests/utilities/20.tuple.cnstr.cpp 
> tests/utilities/20.tuple.creation.cpp 
> tests/utilities/20.tuple.h tests/utilities/20.tuple.helpers
> 
> Btw., here's a prototype of a utility for pretty printing of
> tuple types. It might come in handy as a generic implementation
> of type_name() for tuples, as a replacement for the handful of
> hardwired tuple types we have there.
> 
> 
> #include <cstring>
> #include <tuple>
> 
> template <class T> const char* type_name () { return "???"; }

Should be left undefined so that you get a compile error and can
add the unreferenced type_name() specialization as appropriate.

Also, I'd prefer a compile-time facility for converting types to
strings.  There's really no need for using a function, is there?

> template <> const char* type_name<char>() { return "char"; }
> template <> const char* type_name<short>() { return "short"; }
> template <> const char* type_name<int>() { return "int"; }
> // ...
> 
> template <class ...Types>
> struct Name;
> 
> template <class T>
> struct Name<T> {
>      static void append (char* buf) {
>          std::strcat (buf, type_name<T>());
>      }
> };
> 
> template <>
> struct Name<> {
>      static void append (char*) { }
> };
> 
> template <class T, class ...Types>
> struct Name<T, Types...> {
>      static void append (char *buf) {
>          std::strcat (buf, type_name<T>());
>          std::strcat (buf, ", ");
> 
>          Name<Types...>::append (buf);
>      }
> };
> 
> template <class ...Types>
> char* name (std::tuple<Types...>*)
> {
>      static char buf [256];
> 
>      std::strcpy (buf, "tuple<");
> 
>      Name<Types...>::append (buf);
> 
>      std::strcat (buf, ">");
> 
>      return buf;
> }

I started writing a compile-time version of this but it started to take
too long to write.  Now that I have some extra time though...  :)

Brad.

Mime
View raw message