]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/icl/type_traits/type_to_string.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / icl / type_traits / type_to_string.hpp
1 /*-----------------------------------------------------------------------------+
2 Copyright (c) 2007-2009: Joachim Faulhaber
3 +------------------------------------------------------------------------------+
4 Distributed under the Boost Software License, Version 1.0.
5 (See accompanying file LICENCE.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt)
7 +-----------------------------------------------------------------------------*/
8 #ifndef BOOST_ICL_TYPE_TO_STRING_HPP_JOFA_080416
9 #define BOOST_ICL_TYPE_TO_STRING_HPP_JOFA_080416
10
11 #include <stdio.h>
12 #include <string>
13 #include <sstream>
14
15 #include <boost/type_traits/is_integral.hpp>
16 #include <boost/type_traits/is_float.hpp>
17 #include <boost/mpl/if.hpp>
18
19 namespace boost{ namespace icl
20 {
21 //--------------------------------------------------------------------------
22 template<class Type>
23 struct type_to_string
24 {
25 /** Convert the type to it's typestring */
26 static std::string apply();
27 };
28
29
30 //--------------------------------------------------------------------------
31 template<>inline std::string type_to_string<bool>::apply() { return "bool"; }
32 template<>inline std::string type_to_string<char>::apply() { return "char"; }
33 template<>inline std::string type_to_string<short>::apply(){ return "short"; }
34 template<>inline std::string type_to_string<int>::apply() { return "int"; }
35 template<>inline std::string type_to_string<long>::apply() { return "long"; }
36 template<>inline std::string type_to_string<long long>::apply(){ return "Long"; }
37
38 template<>inline std::string type_to_string<unsigned char>::apply(){ return "char+"; }
39 template<>inline std::string type_to_string<unsigned short>::apply(){ return "short+"; }
40 template<>inline std::string type_to_string<unsigned int>::apply() { return "int+"; }
41 template<>inline std::string type_to_string<unsigned long>::apply() { return "long+"; }
42 template<>inline std::string type_to_string<unsigned long long>::apply(){ return "Long+"; }
43
44 template<>inline std::string type_to_string<float>::apply() { return "flt"; }
45 template<>inline std::string type_to_string<double>::apply() { return "dbl"; }
46
47 //-------------------------------------------------------------------------
48 template<template<class> class Templ>
49 struct unary_template_to_string
50 {
51 static std::string apply();
52 };
53
54 template <template<class>class Unary, class Type>
55 struct type_to_string<Unary<Type> >
56 {
57 static std::string to_string()
58 {
59 return unary_template_to_string<Unary>::apply()+"<"+type_to_string<Type>::apply()+">";
60 }
61 };
62
63 // ---------------------------------------------------------------------------
64 template<template<class,class>class Templ>
65 struct binary_template_to_string
66 {
67 static std::string apply();
68 };
69
70 template <template<class Type1, class Type2>class Binary, class Type1, class Type2>
71 struct type_to_string<Binary<Type1, Type2> >
72 {
73 static std::string apply()
74 {
75 return binary_template_to_string<Binary>::apply()+
76 "<"+type_to_string<Type1>::apply()+","+type_to_string<Type2>::apply()+">";
77 }
78 };
79
80 // ---------------------------------------------------------------------------
81 template<>
82 struct type_to_string<std::string>
83 {
84 static std::string apply() { return "string"; }
85 };
86
87 }} // namespace boost icl
88
89 #endif
90
91