Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 1 | // Boost Lambda Library - is_instance_of.hpp --------------------- |
| 2 | |
| 3 | // Copyright (C) 2001 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi) |
| 4 | // |
| 5 | // Distributed under the Boost Software License, Version 1.0. (See |
| 6 | // accompanying file LICENSE_1_0.txt or copy at |
| 7 | // http://www.boost.org/LICENSE_1_0.txt) |
| 8 | // |
| 9 | // For more information, see www.boost.org |
| 10 | |
| 11 | // --------------------------------------------------------------- |
| 12 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 13 | #ifndef NDNBOOST_LAMBDA_IS_INSTANCE_OF |
| 14 | #define NDNBOOST_LAMBDA_IS_INSTANCE_OF |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 15 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 16 | #include "ndnboost/config.hpp" // for NDNBOOST_STATIC_CONSTANT |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 17 | #include "ndnboost/type_traits/conversion_traits.hpp" // for is_convertible |
| 18 | #include "ndnboost/preprocessor/enum_shifted_params.hpp" |
| 19 | #include "ndnboost/preprocessor/repeat_2nd.hpp" |
| 20 | |
| 21 | // is_instance_of -------------------------------- |
| 22 | // |
| 23 | // is_instance_of_n<A, B>::value is true, if type A is |
| 24 | // an instantiation of a template B, or A derives from an instantiation |
| 25 | // of template B |
| 26 | // |
| 27 | // n is the number of template arguments for B |
| 28 | // |
| 29 | // Example: |
| 30 | // is_instance_of_2<std::istream, basic_stream>::value == true |
| 31 | |
| 32 | // The original implementation was somewhat different, with different versions |
| 33 | // for different compilers. However, there was still a problem |
| 34 | // with gcc.3.0.2 and 3.0.3 compilers, which didn't think regard |
| 35 | // is_instance_of_N<...>::value was a constant. |
| 36 | // John Maddock suggested the way around this problem by building |
| 37 | // is_instance_of templates using ndnboost::is_convertible. |
| 38 | // Now we only have one version of is_instance_of templates, which delagate |
| 39 | // all the nasty compiler tricks to is_convertible. |
| 40 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 41 | #define NDNBOOST_LAMBDA_CLASS(z, N,A) NDNBOOST_PP_COMMA_IF(N) class |
| 42 | #define NDNBOOST_LAMBDA_CLASS_ARG(z, N,A) NDNBOOST_PP_COMMA_IF(N) class A##N |
| 43 | #define NDNBOOST_LAMBDA_ARG(z, N,A) NDNBOOST_PP_COMMA_IF(N) A##N |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 44 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 45 | #define NDNBOOST_LAMBDA_CLASS_LIST(n, NAME) NDNBOOST_PP_REPEAT(n, NDNBOOST_LAMBDA_CLASS, NAME) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 46 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 47 | #define NDNBOOST_LAMBDA_CLASS_ARG_LIST(n, NAME) NDNBOOST_PP_REPEAT(n, NDNBOOST_LAMBDA_CLASS_ARG, NAME) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 48 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 49 | #define NDNBOOST_LAMBDA_ARG_LIST(n, NAME) NDNBOOST_PP_REPEAT(n, NDNBOOST_LAMBDA_ARG, NAME) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 50 | |
| 51 | namespace ndnboost { |
| 52 | namespace lambda { |
| 53 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 54 | #define NDNBOOST_LAMBDA_IS_INSTANCE_OF_TEMPLATE(INDEX) \ |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 55 | \ |
| 56 | namespace detail { \ |
| 57 | \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 58 | template <template<NDNBOOST_LAMBDA_CLASS_LIST(INDEX,T)> class F> \ |
| 59 | struct NDNBOOST_PP_CAT(conversion_tester_,INDEX) { \ |
| 60 | template<NDNBOOST_LAMBDA_CLASS_ARG_LIST(INDEX,A)> \ |
| 61 | NDNBOOST_PP_CAT(conversion_tester_,INDEX) \ |
| 62 | (const F<NDNBOOST_LAMBDA_ARG_LIST(INDEX,A)>&); \ |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 63 | }; \ |
| 64 | \ |
| 65 | } /* end detail */ \ |
| 66 | \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 67 | template <class From, template <NDNBOOST_LAMBDA_CLASS_LIST(INDEX,T)> class To> \ |
| 68 | struct NDNBOOST_PP_CAT(is_instance_of_,INDEX) \ |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 69 | { \ |
| 70 | private: \ |
| 71 | typedef ::ndnboost::is_convertible< \ |
| 72 | From, \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 73 | NDNBOOST_PP_CAT(detail::conversion_tester_,INDEX)<To> \ |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 74 | > helper_type; \ |
| 75 | \ |
| 76 | public: \ |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 77 | NDNBOOST_STATIC_CONSTANT(bool, value = helper_type::value); \ |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 81 | #define NDNBOOST_LAMBDA_HELPER(z, N, A) NDNBOOST_LAMBDA_IS_INSTANCE_OF_TEMPLATE( NDNBOOST_PP_INC(N) ) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 82 | |
| 83 | // Generate the traits for 1-4 argument templates |
| 84 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 85 | NDNBOOST_PP_REPEAT_2ND(4,NDNBOOST_LAMBDA_HELPER,FOO) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 86 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 87 | #undef NDNBOOST_LAMBDA_HELPER |
| 88 | #undef NDNBOOST_LAMBDA_IS_INSTANCE_OF_TEMPLATE |
| 89 | #undef NDNBOOST_LAMBDA_CLASS |
| 90 | #undef NDNBOOST_LAMBDA_ARG |
| 91 | #undef NDNBOOST_LAMBDA_CLASS_ARG |
| 92 | #undef NDNBOOST_LAMBDA_CLASS_LIST |
| 93 | #undef NDNBOOST_LAMBDA_ARG_LIST |
| 94 | #undef NDNBOOST_LAMBDA_CLASS_ARG_LIST |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 95 | |
| 96 | } // lambda |
| 97 | } // boost |
| 98 | |
| 99 | #endif |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |