blob: 1b03597e647a2b1b23d6804d3816eb416abe48c0 [file] [log] [blame]
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001// 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 Thompson3d613fd2013-10-15 15:39:04 -070013#ifndef NDNBOOST_LAMBDA_IS_INSTANCE_OF
14#define NDNBOOST_LAMBDA_IS_INSTANCE_OF
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070015
Jeff Thompson3d613fd2013-10-15 15:39:04 -070016#include "ndnboost/config.hpp" // for NDNBOOST_STATIC_CONSTANT
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070017#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 Thompson3d613fd2013-10-15 15:39:04 -070041#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 Thompsonef2d5a42013-08-22 19:09:24 -070044
Jeff Thompson3d613fd2013-10-15 15:39:04 -070045#define NDNBOOST_LAMBDA_CLASS_LIST(n, NAME) NDNBOOST_PP_REPEAT(n, NDNBOOST_LAMBDA_CLASS, NAME)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070046
Jeff Thompson3d613fd2013-10-15 15:39:04 -070047#define NDNBOOST_LAMBDA_CLASS_ARG_LIST(n, NAME) NDNBOOST_PP_REPEAT(n, NDNBOOST_LAMBDA_CLASS_ARG, NAME)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070048
Jeff Thompson3d613fd2013-10-15 15:39:04 -070049#define NDNBOOST_LAMBDA_ARG_LIST(n, NAME) NDNBOOST_PP_REPEAT(n, NDNBOOST_LAMBDA_ARG, NAME)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070050
51namespace ndnboost {
52namespace lambda {
53
Jeff Thompson3d613fd2013-10-15 15:39:04 -070054#define NDNBOOST_LAMBDA_IS_INSTANCE_OF_TEMPLATE(INDEX) \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070055 \
56namespace detail { \
57 \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070058template <template<NDNBOOST_LAMBDA_CLASS_LIST(INDEX,T)> class F> \
59struct 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 Thompsonef2d5a42013-08-22 19:09:24 -070063}; \
64 \
65} /* end detail */ \
66 \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070067template <class From, template <NDNBOOST_LAMBDA_CLASS_LIST(INDEX,T)> class To> \
68struct NDNBOOST_PP_CAT(is_instance_of_,INDEX) \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070069{ \
70 private: \
71 typedef ::ndnboost::is_convertible< \
72 From, \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070073 NDNBOOST_PP_CAT(detail::conversion_tester_,INDEX)<To> \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070074 > helper_type; \
75 \
76public: \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070077 NDNBOOST_STATIC_CONSTANT(bool, value = helper_type::value); \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070078};
79
80
Jeff Thompson3d613fd2013-10-15 15:39:04 -070081#define NDNBOOST_LAMBDA_HELPER(z, N, A) NDNBOOST_LAMBDA_IS_INSTANCE_OF_TEMPLATE( NDNBOOST_PP_INC(N) )
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070082
83// Generate the traits for 1-4 argument templates
84
Jeff Thompson3d613fd2013-10-15 15:39:04 -070085NDNBOOST_PP_REPEAT_2ND(4,NDNBOOST_LAMBDA_HELPER,FOO)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070086
Jeff Thompson3d613fd2013-10-15 15:39:04 -070087#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 Thompsonef2d5a42013-08-22 19:09:24 -070095
96} // lambda
97} // boost
98
99#endif
100
101
102
103
104