1 
2 // (C) Copyright Tobias Schwinger
3 //
4 // Use modification and distribution are subject to the boost Software License,
5 // Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt).
6 
7 //------------------------------------------------------------------------------
8 // See macro_type_arugment.hpp in this directory for details.
9 
10 #include <string>
11 #include <typeinfo>
12 #include <iostream>
13 
14 #include <boost/mpl/begin_end.hpp>
15 #include <boost/mpl/deref.hpp>
16 
17 #include "macro_type_args.hpp"
18 
19 
20 #define TYPE_NAME(parenthesized_type) \
21     typeid(BOOST_EXAMPLE_MACRO_TYPE_ARGUMENT(parenthesized_type)).name()
22 
23 namespace example
24 {
25   namespace mpl = boost::mpl;
26 
27   template<class Curr, class End>
28   struct mpl_seq_to_string_impl
29   {
getexample::mpl_seq_to_string_impl30     static std::string get(std::string const & prev)
31     {
32       typedef typename mpl::next<Curr>::type next_pos;
33       typedef typename mpl::deref<Curr>::type type;
34 
35       return mpl_seq_to_string_impl<next_pos,End>::get(
36           prev + (prev.empty()? '\0' : ',') + typeid(type).name() );
37     }
38   };
39   template<class End>
40   struct mpl_seq_to_string_impl<End, End>
41   {
getexample::mpl_seq_to_string_impl42     static std::string get(std::string const & prev)
43     {
44       return prev;
45     }
46   };
47 
48   template<class Seq>
mpl_seq_to_string()49   std::string mpl_seq_to_string()
50   {
51     typedef typename mpl::begin<Seq>::type begin;
52     typedef typename mpl::end<Seq>::type end;
53 
54     return mpl_seq_to_string_impl<begin, end>::get("");
55   }
56 
57 }
58 
59 #define TYPE_NAMES(parenthesized_types) \
60     ::example::mpl_seq_to_string< \
61         BOOST_EXAMPLE_MACRO_TYPE_LIST_ARGUMENT(parenthesized_types) >()
62 
main()63 int main()
64 {
65   std::cout << TYPE_NAME((int)) << std::endl;
66 
67   std::cout << TYPE_NAMES((int,char)) << std::endl;
68   std::cout << TYPE_NAMES((int,char,long)) << std::endl;
69 
70 }
71 
72