function_detector.hpp 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2009-2012.
  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. #ifndef BOOST_CONTAINER_DETAIL_FUNCTION_DETECTOR_HPP
  22. #define BOOST_CONTAINER_DETAIL_FUNCTION_DETECTOR_HPP
  23. #include <boost/container/detail/config_begin.hpp>
  24. namespace boost {
  25. namespace container {
  26. namespace function_detector {
  27. typedef char NotFoundType;
  28. struct StaticFunctionType { NotFoundType x [2]; };
  29. struct NonStaticFunctionType { NotFoundType x [3]; };
  30. enum
  31. { NotFound = 0,
  32. StaticFunction = sizeof( StaticFunctionType ) - sizeof( NotFoundType ),
  33. NonStaticFunction = sizeof( NonStaticFunctionType ) - sizeof( NotFoundType )
  34. };
  35. } //namespace boost {
  36. } //namespace container {
  37. } //namespace function_detector {
  38. #define BOOST_CONTAINER_CREATE_FUNCTION_DETECTOR(Identifier, InstantiationKey) \
  39. namespace boost { \
  40. namespace container { \
  41. namespace function_detector { \
  42. template < class T, \
  43. class NonStaticType, \
  44. class NonStaticConstType, \
  45. class StaticType > \
  46. class DetectMember_##InstantiationKey_##Identifier { \
  47. template < NonStaticType > \
  48. struct TestNonStaticNonConst ; \
  49. \
  50. template < NonStaticConstType > \
  51. struct TestNonStaticConst ; \
  52. \
  53. template < StaticType > \
  54. struct TestStatic ; \
  55. \
  56. template <class U > \
  57. static NonStaticFunctionType Test( TestNonStaticNonConst<&U::Identifier>*, int ); \
  58. \
  59. template <class U > \
  60. static NonStaticFunctionType Test( TestNonStaticConst<&U::Identifier>*, int ); \
  61. \
  62. template <class U> \
  63. static StaticFunctionType Test( TestStatic<&U::Identifier>*, int ); \
  64. \
  65. template <class U> \
  66. static NotFoundType Test( ... ); \
  67. public : \
  68. static const int check = NotFound + (sizeof(Test<T>(0, 0)) - sizeof(NotFoundType));\
  69. };\
  70. }}} //namespace boost::container::function_detector {
  71. #define BOOST_CONTAINER_DETECT_FUNCTION(Class, InstantiationKey, ReturnType, Identifier, Params) \
  72. ::boost::container::function_detector::DetectMember_##InstantiationKey_##Identifier< Class,\
  73. ReturnType (Class::*)Params,\
  74. ReturnType (Class::*)Params const,\
  75. ReturnType (*)Params \
  76. >::check
  77. #include <boost/container/detail/config_end.hpp>
  78. #endif //@ifndef BOOST_CONTAINER_DETAIL_FUNCTION_DETECTOR_HPP