function_detector.hpp 3.5 KB

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