1 /*-----------------------------------------------------------------------------+
2 Copyright (c) 2008-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_TRAITS_REP_TYPE_OF_HPP_JOFA_110329
9 #define BOOST_ICL_TYPE_TRAITS_REP_TYPE_OF_HPP_JOFA_110329
10 
11 #include <boost/config.hpp> // For macro BOOST_STATIC_CONSTANT
12 #include <boost/mpl/has_xxx.hpp>
13 #include <boost/mpl/or.hpp>
14 #include <boost/mpl/and.hpp>
15 #include <boost/mpl/not.hpp>
16 #include <boost/type_traits/is_same.hpp>
17 #include <boost/icl/type_traits/no_type.hpp>
18 
19 namespace boost{ namespace icl
20 {
21     namespace detail
22     {
23         BOOST_MPL_HAS_XXX_TRAIT_DEF(rep)
24     }
25 
26     //--------------------------------------------------------------------------
27     template <class Type>
28     struct has_rep_type
29       : mpl::bool_<detail::has_rep<Type>::value>
30     {};
31 
32     template <class Rep, class Type>
33     struct represents // Rep represents Type;  Type is_wrapper_of Rep
34       : mpl::bool_<detail::has_rep<Type>::value>
35     {
36         typedef represents type;
37         BOOST_STATIC_CONSTANT(bool,
38             value = (mpl::and_< has_rep_type<Type>
39                               , boost::is_same<typename Type::rep, Rep> >::value)
40             );
41     };
42 
43     //--------------------------------------------------------------------------
44     template <class Type, bool has_rep>
45     struct get_rep_type;
46 
47     template <class Type>
48     struct get_rep_type<Type, false>
49     {
50         typedef no_type type;
51     };
52 
53     template <class Type>
54     struct get_rep_type<Type, true>
55     {
56         typedef typename Type::rep type;
57     };
58 
59     //--------------------------------------------------------------------------
60     template<class Type>
61     struct rep_type_of
62     {
63         typedef typename
64             get_rep_type<Type, has_rep_type<Type>::value>::type type;
65     };
66 
67 }} // namespace boost icl
68 
69 #endif
70