source: NonGTP/Boost/boost/ptr_container/detail/is_convertible.hpp @ 857

Revision 857, 2.5 KB checked in by igarcia, 19 years ago (diff)
Line 
1// (C) Copyright Thorsten Ottosen 2005
2// (C) Copyright Howard Hinnant 2004
3// (C) Copyright Jonathan Turkanis 2004
4// Distributed under the Boost Software License, Version 1.0. (See accompanying
5// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
6
7//
8// Contains type traits machinery for incomplete arrays. MPL compatibility
9// is included for completeness, but is not necessary for the current
10// application.
11//
12
13#ifndef BOOST_MOVE_PTR_ARRAYS_HPP_INCLUDED
14#define BOOST_MOVE_PTR_ARRAYS_HPP_INCLUDED
15
16#include <boost/config.hpp> // BOOST_STATIC_CONSTANT.
17#include <boost/mpl/aux_/lambda_support.hpp>
18#include <boost/mpl/and.hpp>
19#include <boost/mpl/bool.hpp>
20#include <boost/mpl/identity.hpp>
21#include <boost/mpl/if.hpp>
22#include <boost/type_traits/is_array.hpp>
23#include <boost/type_traits/is_convertible.hpp>
24#include <boost/type_traits/is_same.hpp>
25#include <boost/type_traits/remove_bounds.hpp>
26#include <boost/type_traits/remove_cv.hpp>
27#include <boost/utility/enable_if.hpp>
28
29namespace boost { namespace ptr_container_detail { namespace move_ptrs {
30
31// From Howard Hinnant.
32template<typename T, typename U>
33struct is_array_convertible {
34    typedef typename remove_bounds<T>::type      t_element;
35    typedef typename remove_bounds<U>::type      u_element;
36    typedef typename remove_cv<t_element>::type  t_base;
37    typedef typename remove_cv<u_element>::type  u_base;
38    typedef typename
39            mpl::and_<
40                is_array<T>,
41                is_array<U>,
42                is_same<t_base, u_base>,
43                is_convertible<t_element*, u_element*>
44            >::type                                     type;
45    BOOST_STATIC_CONSTANT(bool, value = type::value);
46    BOOST_MPL_AUX_LAMBDA_SUPPORT(2, is_array_convertible, (T, U))
47};
48
49template<typename T, typename U>
50struct is_smart_ptr_convertible
51    : mpl::if_<
52          is_array<T>,
53          is_array_convertible<T, U>,
54          is_convertible<T*, U*>
55      >::type
56    { };
57
58#ifndef BOOST_NO_SFINAE
59    template<typename Src, typename Tgt, typename T = void>
60    struct enable_if_convertible
61        : enable_if<
62              is_smart_ptr_convertible<Src, Tgt>,
63              T
64          >
65        { };
66#else
67    template<typename Src, typename Tgt, class T >
68    struct enable_if_convertible : mpl::identity<T> { };
69#endif
70
71} } }         // End namespaces ptr_container_detail, move_ptrs, boost.
72
73#endif      // #ifndef BOOST_MOVE_PTR_ARRAYS_HPP_INCLUDED
Note: See TracBrowser for help on using the repository browser.