epoc32/include/stdapis/boost/lambda/detail/is_instance_of.hpp
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
williamr@2
     1
// Boost Lambda Library - is_instance_of.hpp ---------------------
williamr@2
     2
williamr@2
     3
// Copyright (C) 2001 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
williamr@2
     4
//
williamr@2
     5
// Distributed under the Boost Software License, Version 1.0. (See
williamr@2
     6
// accompanying file LICENSE_1_0.txt or copy at
williamr@2
     7
// http://www.boost.org/LICENSE_1_0.txt)
williamr@2
     8
//
williamr@2
     9
// For more information, see www.boost.org
williamr@2
    10
williamr@2
    11
// ---------------------------------------------------------------
williamr@2
    12
williamr@2
    13
#ifndef BOOST_LAMBDA_IS_INSTANCE_OF
williamr@2
    14
#define BOOST_LAMBDA_IS_INSTANCE_OF
williamr@2
    15
williamr@2
    16
#include "boost/config.hpp" // for BOOST_STATIC_CONSTANT
williamr@2
    17
#include "boost/type_traits/conversion_traits.hpp" // for is_convertible
williamr@2
    18
#include "boost/preprocessor/enum_shifted_params.hpp"
williamr@2
    19
#include "boost/preprocessor/repeat_2nd.hpp"
williamr@2
    20
williamr@2
    21
// is_instance_of --------------------------------
williamr@2
    22
// 
williamr@2
    23
// is_instance_of_n<A, B>::value is true, if type A is 
williamr@2
    24
// an instantiation of a template B, or A derives from an instantiation 
williamr@2
    25
// of template B
williamr@2
    26
//
williamr@2
    27
// n is the number of template arguments for B
williamr@2
    28
// 
williamr@2
    29
// Example:
williamr@2
    30
// is_instance_of_2<std::istream, basic_stream>::value == true
williamr@2
    31
williamr@2
    32
// The original implementation was somewhat different, with different versions
williamr@2
    33
// for different compilers. However, there was still a problem
williamr@2
    34
// with gcc.3.0.2 and 3.0.3 compilers, which didn't think regard
williamr@2
    35
// is_instance_of_N<...>::value was a constant.
williamr@2
    36
// John Maddock suggested the way around this problem by building 
williamr@2
    37
// is_instance_of templates using boost::is_convertible.
williamr@2
    38
// Now we only have one version of is_instance_of templates, which delagate
williamr@2
    39
// all the nasty compiler tricks to is_convertible. 
williamr@2
    40
williamr@2
    41
#define BOOST_LAMBDA_CLASS(z, N,A) BOOST_PP_COMMA_IF(N) class
williamr@2
    42
#define BOOST_LAMBDA_CLASS_ARG(z, N,A) BOOST_PP_COMMA_IF(N) class A##N 
williamr@2
    43
#define BOOST_LAMBDA_ARG(z, N,A) BOOST_PP_COMMA_IF(N) A##N 
williamr@2
    44
williamr@2
    45
#define BOOST_LAMBDA_CLASS_LIST(n, NAME) BOOST_PP_REPEAT(n, BOOST_LAMBDA_CLASS, NAME)
williamr@2
    46
williamr@2
    47
#define BOOST_LAMBDA_CLASS_ARG_LIST(n, NAME) BOOST_PP_REPEAT(n, BOOST_LAMBDA_CLASS_ARG, NAME)
williamr@2
    48
williamr@2
    49
#define BOOST_LAMBDA_ARG_LIST(n, NAME) BOOST_PP_REPEAT(n, BOOST_LAMBDA_ARG, NAME)
williamr@2
    50
williamr@2
    51
namespace boost {
williamr@2
    52
namespace lambda {
williamr@2
    53
williamr@2
    54
#define BOOST_LAMBDA_IS_INSTANCE_OF_TEMPLATE(INDEX)                         \
williamr@2
    55
                                                                            \
williamr@2
    56
namespace detail {                                                          \
williamr@2
    57
                                                                            \
williamr@2
    58
template <template<BOOST_LAMBDA_CLASS_LIST(INDEX,T)> class F>               \
williamr@2
    59
struct BOOST_PP_CAT(conversion_tester_,INDEX) {                             \
williamr@2
    60
  template<BOOST_LAMBDA_CLASS_ARG_LIST(INDEX,A)>                            \
williamr@2
    61
  BOOST_PP_CAT(conversion_tester_,INDEX)                                    \
williamr@2
    62
    (const F<BOOST_LAMBDA_ARG_LIST(INDEX,A)>&);                             \
williamr@2
    63
};                                                                          \
williamr@2
    64
                                                                            \
williamr@2
    65
} /* end detail */                                                          \
williamr@2
    66
                                                                            \
williamr@2
    67
template <class From, template <BOOST_LAMBDA_CLASS_LIST(INDEX,T)> class To> \
williamr@2
    68
struct BOOST_PP_CAT(is_instance_of_,INDEX)                                  \
williamr@2
    69
{                                                                           \
williamr@2
    70
 private:                                                                   \
williamr@2
    71
   typedef ::boost::is_convertible<                                         \
williamr@2
    72
     From,                                                                  \
williamr@2
    73
     BOOST_PP_CAT(detail::conversion_tester_,INDEX)<To>                     \
williamr@2
    74
   > helper_type;                                                           \
williamr@2
    75
                                                                            \
williamr@2
    76
public:                                                                     \
williamr@2
    77
  BOOST_STATIC_CONSTANT(bool, value = helper_type::value);                  \
williamr@2
    78
};
williamr@2
    79
williamr@2
    80
williamr@2
    81
#define BOOST_LAMBDA_HELPER(z, N, A) BOOST_LAMBDA_IS_INSTANCE_OF_TEMPLATE( BOOST_PP_INC(N) )
williamr@2
    82
williamr@2
    83
// Generate the traits for 1-4 argument templates
williamr@2
    84
williamr@2
    85
BOOST_PP_REPEAT_2ND(4,BOOST_LAMBDA_HELPER,FOO)
williamr@2
    86
williamr@2
    87
#undef BOOST_LAMBDA_HELPER
williamr@2
    88
#undef BOOST_LAMBDA_IS_INSTANCE_OF_TEMPLATE
williamr@2
    89
#undef BOOST_LAMBDA_CLASS
williamr@2
    90
#undef BOOST_LAMBDA_ARG
williamr@2
    91
#undef BOOST_LAMBDA_CLASS_ARG
williamr@2
    92
#undef BOOST_LAMBDA_CLASS_LIST
williamr@2
    93
#undef BOOST_LAMBDA_ARG_LIST
williamr@2
    94
#undef BOOST_LAMBDA_CLASS_ARG_LIST
williamr@2
    95
williamr@2
    96
} // lambda
williamr@2
    97
} // boost
williamr@2
    98
williamr@2
    99
#endif
williamr@2
   100
williamr@2
   101
williamr@2
   102
williamr@2
   103
williamr@2
   104