1 /////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga  2009-2013.
4 //
5 // Distributed under the Boost Software License, Version 1.0.
6 //    (See accompanying file LICENSE_1_0.txt or copy at
7 //          http://www.boost.org/LICENSE_1_0.txt)
8 //
9 // See http://www.boost.org/libs/container for documentation.
10 //
11 /////////////////////////////////////////////////////////////////////////////
12 //  This code was modified from the code posted by Alexandre Courpron in his
13 //  article "Interface Detection" in The Code Project:
14 //  http://www.codeproject.com/KB/architecture/Detector.aspx
15 ///////////////////////////////////////////////////////////////////////////////
16 // Copyright 2007 Alexandre Courpron
17 //
18 // Permission to use, copy, modify, redistribute and sell this software,
19 // provided that this copyright notice appears on all copies of the software.
20 ///////////////////////////////////////////////////////////////////////////////
21 
22 #ifndef BOOST_CONTAINER_DETAIL_FUNCTION_DETECTOR_HPP
23 #define BOOST_CONTAINER_DETAIL_FUNCTION_DETECTOR_HPP
24 
25 #ifndef BOOST_CONFIG_HPP
26 #  include <boost/config.hpp>
27 #endif
28 
29 #if defined(BOOST_HAS_PRAGMA_ONCE)
30 #  pragma once
31 #endif
32 
33 #include <boost/container/detail/config_begin.hpp>
34 
35 namespace boost {
36 namespace container {
37 namespace function_detector {
38 
39     typedef char NotFoundType;
40     struct StaticFunctionType { NotFoundType x [2]; };
41     struct NonStaticFunctionType { NotFoundType x [3]; };
42 
43     enum
44          { NotFound          = 0,
45            StaticFunction    = sizeof( StaticFunctionType )    - sizeof( NotFoundType ),
46            NonStaticFunction = sizeof( NonStaticFunctionType ) - sizeof( NotFoundType )
47          };
48 
49 }  //namespace boost {
50 }  //namespace container {
51 }  //namespace function_detector {
52 
53 #define BOOST_CONTAINER_CREATE_FUNCTION_DETECTOR(Identifier, InstantiationKey) \
54    namespace boost { \
55    namespace container { \
56    namespace function_detector { \
57    template < class T, \
58             class NonStaticType, \
59             class NonStaticConstType, \
60             class StaticType > \
61    class DetectMember_##InstantiationKey_##Identifier { \
62       template < NonStaticType > \
63       struct TestNonStaticNonConst ; \
64       \
65       template < NonStaticConstType > \
66       struct TestNonStaticConst ; \
67       \
68       template < StaticType > \
69       struct TestStatic ; \
70       \
71       template <class U > \
72       static NonStaticFunctionType Test( TestNonStaticNonConst<&U::Identifier>*, int ); \
73       \
74       template <class U > \
75       static NonStaticFunctionType Test( TestNonStaticConst<&U::Identifier>*, int ); \
76       \
77       template <class U> \
78       static StaticFunctionType Test( TestStatic<&U::Identifier>*, int ); \
79       \
80       template <class U> \
81       static NotFoundType Test( ... ); \
82    public : \
83       static const int check = NotFound + (sizeof(Test<T>(0, 0)) - sizeof(NotFoundType));\
84    };\
85 }}} //namespace boost::container::function_detector {
86 
87 #define BOOST_CONTAINER_DETECT_FUNCTION(Class, InstantiationKey, ReturnType, Identifier, Params) \
88     ::boost::container::function_detector::DetectMember_##InstantiationKey_##Identifier< Class,\
89                                          ReturnType (Class::*)Params,\
90                                          ReturnType (Class::*)Params const,\
91                                          ReturnType (*)Params \
92                                        >::check
93 
94 #include <boost/container/detail/config_end.hpp>
95 
96 #endif   //@ifndef BOOST_CONTAINER_DETAIL_FUNCTION_DETECTOR_HPP
97