blob: d00bd2fb6b940bd860cd6bd11955df7946849b1f [file] [log] [blame]
Jeff Thompsonf7d49942013-08-01 16:47:40 -07001
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
5
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.
11
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).
19
20
Jeff Thompson3d613fd2013-10-15 15:39:04 -070021#ifndef NDNBOOST_TT_IS_SAME_HPP_INCLUDED
22#define NDNBOOST_TT_IS_SAME_HPP_INCLUDED
Jeff Thompsonf7d49942013-08-01 16:47:40 -070023
Jeff Thompson2277ce52013-08-01 17:34:11 -070024#include <ndnboost/type_traits/config.hpp>
Jeff Thompson3d613fd2013-10-15 15:39:04 -070025#ifdef NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompson2277ce52013-08-01 17:34:11 -070026#include <ndnboost/type_traits/detail/yes_no_type.hpp>
27#include <ndnboost/type_traits/detail/ice_and.hpp>
28#include <ndnboost/type_traits/is_reference.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070029#endif
30// should be the last #include
Jeff Thompson2277ce52013-08-01 17:34:11 -070031#include <ndnboost/type_traits/detail/bool_trait_def.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070032
33namespace ndnboost {
34
Jeff Thompson3d613fd2013-10-15 15:39:04 -070035#ifndef NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsonf7d49942013-08-01 16:47:40 -070036
Jeff Thompson3d613fd2013-10-15 15:39:04 -070037NDNBOOST_TT_AUX_BOOL_TRAIT_DEF2(is_same,T,U,false)
38NDNBOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC2_1(typename T,is_same,T,T,true)
39#if NDNBOOST_WORKAROUND(__BORLANDC__, < 0x600)
Jeff Thompsonf7d49942013-08-01 16:47:40 -070040// without this, Borland's compiler gives the wrong answer for
41// references to arrays:
Jeff Thompson3d613fd2013-10-15 15:39:04 -070042NDNBOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC2_1(typename T,is_same,T&,T&,true)
Jeff Thompsonf7d49942013-08-01 16:47:40 -070043#endif
44
Jeff Thompson3d613fd2013-10-15 15:39:04 -070045#else // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsonf7d49942013-08-01 16:47:40 -070046
47namespace detail {
48
Jeff Thompson3d613fd2013-10-15 15:39:04 -070049#ifdef NDNBOOST_MSVC
Jeff Thompsonf7d49942013-08-01 16:47:40 -070050// the following VC6 specific implementation is *NOT* legal
51// C++, but has the advantage that it works for incomplete
52// types.
53
54template< typename T1 >
55struct is_same_part_1
56{
57 template<typename T2> struct part_2 { enum { value = false }; };
58 template<> struct part_2<T1> { enum { value = true }; };
59};
60
61template< typename T1, typename T2 >
62struct is_same_impl
63{
64 enum { value = ndnboost::detail::is_same_part_1<T1>::template part_2<T2>::value };
65};
66
67#else // generic "no-partial-specialization" version
68
69template <typename T>
70::ndnboost::type_traits::yes_type
Jeff Thompson3d613fd2013-10-15 15:39:04 -070071NDNBOOST_TT_DECL is_same_tester(T*, T*);
Jeff Thompsonf7d49942013-08-01 16:47:40 -070072
73::ndnboost::type_traits::no_type
Jeff Thompson3d613fd2013-10-15 15:39:04 -070074NDNBOOST_TT_DECL is_same_tester(...);
Jeff Thompsonf7d49942013-08-01 16:47:40 -070075
76template <typename T, typename U>
77struct is_same_impl
78{
79 static T t;
80 static U u;
81
Jeff Thompson3d613fd2013-10-15 15:39:04 -070082 NDNBOOST_STATIC_CONSTANT(bool, value =
Jeff Thompsonf7d49942013-08-01 16:47:40 -070083 (::ndnboost::type_traits::ice_and<
84 (sizeof(type_traits::yes_type) == sizeof(ndnboost::detail::is_same_tester(&t,&u))),
85 (::ndnboost::is_reference<T>::value == ::ndnboost::is_reference<U>::value),
86 (sizeof(T) == sizeof(U))
87 >::value));
88};
89
Jeff Thompson3d613fd2013-10-15 15:39:04 -070090#endif // NDNBOOST_MSVC
Jeff Thompsonf7d49942013-08-01 16:47:40 -070091
92} // namespace detail
93
Jeff Thompson3d613fd2013-10-15 15:39:04 -070094NDNBOOST_TT_AUX_BOOL_TRAIT_DEF2(is_same,T,U,(::ndnboost::detail::is_same_impl<T,U>::value))
Jeff Thompsonf7d49942013-08-01 16:47:40 -070095
Jeff Thompson3d613fd2013-10-15 15:39:04 -070096#endif // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsonf7d49942013-08-01 16:47:40 -070097
98} // namespace ndnboost
99
Jeff Thompson2277ce52013-08-01 17:34:11 -0700100#include <ndnboost/type_traits/detail/bool_trait_undef.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700101
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700102#endif // NDNBOOST_TT_IS_SAME_HPP_INCLUDED
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700103