Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:44:47

0001 // Boost Lambda Library - is_instance_of.hpp ---------------------
0002 
0003 // Copyright (C) 2001 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
0004 //
0005 // Distributed under the Boost Software License, Version 1.0. (See
0006 // accompanying file LICENSE_1_0.txt or copy at
0007 // http://www.boost.org/LICENSE_1_0.txt)
0008 //
0009 // For more information, see www.boost.org
0010 
0011 // ---------------------------------------------------------------
0012 
0013 #ifndef BOOST_LAMBDA_IS_INSTANCE_OF
0014 #define BOOST_LAMBDA_IS_INSTANCE_OF
0015 
0016 #include "boost/config.hpp" // for BOOST_STATIC_CONSTANT
0017 #include "boost/type_traits/conversion_traits.hpp" // for is_convertible
0018 #include "boost/preprocessor/enum_shifted_params.hpp"
0019 #include "boost/preprocessor/repeat_2nd.hpp"
0020 
0021 // is_instance_of --------------------------------
0022 // 
0023 // is_instance_of_n<A, B>::value is true, if type A is 
0024 // an instantiation of a template B, or A derives from an instantiation 
0025 // of template B
0026 //
0027 // n is the number of template arguments for B
0028 // 
0029 // Example:
0030 // is_instance_of_2<std::istream, basic_stream>::value == true
0031 
0032 // The original implementation was somewhat different, with different versions
0033 // for different compilers. However, there was still a problem
0034 // with gcc.3.0.2 and 3.0.3 compilers, which didn't think regard
0035 // is_instance_of_N<...>::value was a constant.
0036 // John Maddock suggested the way around this problem by building 
0037 // is_instance_of templates using boost::is_convertible.
0038 // Now we only have one version of is_instance_of templates, which delagate
0039 // all the nasty compiler tricks to is_convertible. 
0040 
0041 #define BOOST_LAMBDA_CLASS(z, N,A) BOOST_PP_COMMA_IF(N) class
0042 #define BOOST_LAMBDA_CLASS_ARG(z, N,A) BOOST_PP_COMMA_IF(N) class A##N 
0043 #define BOOST_LAMBDA_ARG(z, N,A) BOOST_PP_COMMA_IF(N) A##N 
0044 
0045 #define BOOST_LAMBDA_CLASS_LIST(n, NAME) BOOST_PP_REPEAT(n, BOOST_LAMBDA_CLASS, NAME)
0046 
0047 #define BOOST_LAMBDA_CLASS_ARG_LIST(n, NAME) BOOST_PP_REPEAT(n, BOOST_LAMBDA_CLASS_ARG, NAME)
0048 
0049 #define BOOST_LAMBDA_ARG_LIST(n, NAME) BOOST_PP_REPEAT(n, BOOST_LAMBDA_ARG, NAME)
0050 
0051 namespace boost {
0052 namespace lambda {
0053 
0054 #define BOOST_LAMBDA_IS_INSTANCE_OF_TEMPLATE(INDEX)                         \
0055                                                                             \
0056 namespace detail {                                                          \
0057                                                                             \
0058 template <template<BOOST_LAMBDA_CLASS_LIST(INDEX,T)> class F>               \
0059 struct BOOST_PP_CAT(conversion_tester_,INDEX) {                             \
0060   template<BOOST_LAMBDA_CLASS_ARG_LIST(INDEX,A)>                            \
0061   BOOST_PP_CAT(conversion_tester_,INDEX)                                    \
0062     (const F<BOOST_LAMBDA_ARG_LIST(INDEX,A)>&);                             \
0063 };                                                                          \
0064                                                                             \
0065 } /* end detail */                                                          \
0066                                                                             \
0067 template <class From, template <BOOST_LAMBDA_CLASS_LIST(INDEX,T)> class To> \
0068 struct BOOST_PP_CAT(is_instance_of_,INDEX)                                  \
0069 {                                                                           \
0070  private:                                                                   \
0071    typedef ::boost::is_convertible<                                         \
0072      From,                                                                  \
0073      BOOST_PP_CAT(detail::conversion_tester_,INDEX)<To>                     \
0074    > helper_type;                                                           \
0075                                                                             \
0076 public:                                                                     \
0077   BOOST_STATIC_CONSTANT(bool, value = helper_type::value);                  \
0078 };
0079 
0080 
0081 #define BOOST_LAMBDA_HELPER(z, N, A) BOOST_LAMBDA_IS_INSTANCE_OF_TEMPLATE( BOOST_PP_INC(N) )
0082 
0083 // Generate the traits for 1-4 argument templates
0084 
0085 BOOST_PP_REPEAT_2ND(4,BOOST_LAMBDA_HELPER,FOO)
0086 
0087 #undef BOOST_LAMBDA_HELPER
0088 #undef BOOST_LAMBDA_IS_INSTANCE_OF_TEMPLATE
0089 #undef BOOST_LAMBDA_CLASS
0090 #undef BOOST_LAMBDA_ARG
0091 #undef BOOST_LAMBDA_CLASS_ARG
0092 #undef BOOST_LAMBDA_CLASS_LIST
0093 #undef BOOST_LAMBDA_ARG_LIST
0094 #undef BOOST_LAMBDA_CLASS_ARG_LIST
0095 
0096 } // lambda
0097 } // boost
0098 
0099 #endif
0100 
0101 
0102 
0103 
0104