fix doc example typo
[boost.git] / boost / type_traits / is_same.hpp
blobe0d1808b4d1def169ed354091b095c9bf7a40cd8
2 // (C) Copyright Dave Abrahams, Steve Cleary, Beman Dawes,
3 // Howard Hinnant and John Maddock 2000.
4 // (C) Copyright Mat Marcus, Jesse Jones and Adobe Systems Inc 2001
6 // Use, modification and distribution are subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt).
9 //
10 // See http://www.boost.org/libs/type_traits for most recent version including documentation.
12 // Fixed is_pointer, is_reference, is_const, is_volatile, is_same,
13 // is_member_pointer based on the Simulated Partial Specialization work
14 // of Mat Marcus and Jesse Jones. See http://opensource.adobe.com or
15 // http://groups.yahoo.com/group/boost/message/5441
16 // Some workarounds in here use ideas suggested from "Generic<Programming>:
17 // Mappings between Types and Values"
18 // by Andrei Alexandrescu (see http://www.cuj.com/experts/1810/alexandr.html).
21 #ifndef BOOST_TT_IS_SAME_HPP_INCLUDED
22 #define BOOST_TT_IS_SAME_HPP_INCLUDED
24 #include <boost/type_traits/config.hpp>
25 #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
26 #include <boost/type_traits/detail/yes_no_type.hpp>
27 #include <boost/type_traits/detail/ice_and.hpp>
28 #include <boost/type_traits/is_reference.hpp>
29 #endif
30 // should be the last #include
31 #include <boost/type_traits/detail/bool_trait_def.hpp>
33 namespace boost {
35 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
37 BOOST_TT_AUX_BOOL_TRAIT_DEF2(is_same,T,U,false)
38 BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC2_1(typename T,is_same,T,T,true)
39 #if BOOST_WORKAROUND(__BORLANDC__, < 0x600)
40 // without this, Borland's compiler gives the wrong answer for
41 // references to arrays:
42 BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC2_1(typename T,is_same,T&,T&,true)
43 #endif
45 #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
47 namespace detail {
49 #ifdef BOOST_MSVC
50 // the following VC6 specific implementation is *NOT* legal
51 // C++, but has the advantage that it works for incomplete
52 // types.
54 template< typename T1 >
55 struct is_same_part_1
57 template<typename T2> struct part_2 { enum { value = false }; };
58 template<> struct part_2<T1> { enum { value = true }; };
61 template< typename T1, typename T2 >
62 struct is_same_impl
64 enum { value = detail::is_same_part_1<T1>::template part_2<T2>::value };
67 #else // generic "no-partial-specialization" version
69 template <typename T>
70 ::boost::type_traits::yes_type
71 BOOST_TT_DECL is_same_tester(T*, T*);
73 ::boost::type_traits::no_type
74 BOOST_TT_DECL is_same_tester(...);
76 template <typename T, typename U>
77 struct is_same_impl
79 static T t;
80 static U u;
82 BOOST_STATIC_CONSTANT(bool, value =
83 (::boost::type_traits::ice_and<
84 (sizeof(type_traits::yes_type) == sizeof(detail::is_same_tester(&t,&u))),
85 (::boost::is_reference<T>::value == ::boost::is_reference<U>::value),
86 (sizeof(T) == sizeof(U))
87 >::value));
90 #endif // BOOST_MSVC
92 } // namespace detail
94 BOOST_TT_AUX_BOOL_TRAIT_DEF2(is_same,T,U,(::boost::detail::is_same_impl<T,U>::value))
96 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
98 } // namespace boost
100 #include <boost/type_traits/detail/bool_trait_undef.hpp>
102 #endif // BOOST_TT_IS_SAME_HPP_INCLUDED