tti_nested_type_and_signatures.qbk 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. [/
  2. (C) Copyright Edward Diener 2011,2012
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. ]
  7. [section:tti_func_sig Nested Types and Function Signatures]
  8. The strength of `BOOST_TTI_MEMBER_TYPE` to represent a type which may or may not exist, and which
  9. then can be subsequently used in other macro metafunctions whenever a type is needed as a template
  10. parameter without producing a compiler error, should not be underestimated. It is one of the
  11. reasons why we have two different ways of using our generated metafunction when introspecting
  12. for member data, a member function, or a static member function of an enclosing type.
  13. In the cases where we specify a composite syntax when using `BOOST_TTI_HAS_MEMBER_DATA`,
  14. `BOOST_TTI_HAS_MEMBER_FUNCTION`, or `BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION`, the signature
  15. for the member data, member function, or static member function is a single type. For
  16. `BOOST_TTI_HAS_MEMBER_DATA` the signature is a pointer to member data, for
  17. `BOOST_TTI_HAS_MEMBER_FUNCTION` the signature is a pointer to a member function, and for
  18. `BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION` the signature is divided between an enclosing type
  19. and a function in composite format. This makes for a syntactical notation which is natural
  20. to specify, but because of the notation we can not use the nested type functionality in
  21. `BOOST_TTI_MEMBER_TYPE` for potential parts of these composite types. If any part of this
  22. signature, which specifies a composite of various types, is invalid, a compiler time error
  23. will occur.
  24. But in the more specific cases, when we use `BOOST_TTI_HAS_MEMBER_DATA`,
  25. `BOOST_TTI_HAS_MEMBER_FUNCTION`, and `BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION`, our composite
  26. type in our signatures is broken down into their individual types so that using
  27. `BOOST_TTI_MEMBER_TYPE` for any one of the individual types will not lead to a compile time
  28. error if the type specified does not actually exist.
  29. A few examples will suffice.
  30. Given known types T and U, and the supposed type Ntype as a
  31. nested type of U, we want to find out if type T has a member function whose signature is
  32. `void aMemberFunction(U::Ntype)`.
  33. First using `BOOST_TTI_HAS_MEMBER_FUNCTION` using our composite form we would code:
  34. #include <boost/tti/has_member_function.hpp>
  35. BOOST_TTI_HAS_MEMBER_FUNCTION(aMemberFunction)
  36. has_member_function_aMemberFunction<void (T::*)(U::Ntype)>::value;
  37. If the nested type U::Ntype does not exist, this leads to a compiler error.
  38. We really want to avoid this situation, so let's try our alternative.
  39. Second using `BOOST_TTI_HAS_MEMBER_FUNCTION` using our specific form we would code:
  40. #include <boost/tti/member_type.hpp>
  41. #include <boost/tti/has_member_function.hpp>
  42. BOOST_TTI_HAS_MEMBER_TYPE(Ntype)
  43. BOOST_TTI_HAS_MEMBER_FUNCTION(aMemberFunction)
  44. typedef typename has_member_type_Ntype<U>::type OurType;
  45. has_member_function_aMemberFunction<T,void,boost::mpl::vector<OurType> >::value;
  46. If the nested type U::Ntype does exist and T does have a member function
  47. whose signature is `void aMemberFunction(U::Ntype)` our 'value' is true,
  48. otherwise it is false. We will never get a compiler error in this case.
  49. As a second example we will once again use the suppositions of our first
  50. example; given known types T and U, and the supposed type Ntype as a
  51. nested type of U. But this time let us look for a static member function
  52. whose signature is `void aStaticMemberFunction(U::Ntype)`.
  53. First using `BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION` using our composite form we would code:
  54. #include <boost/tti/has_static_member_function.hpp>
  55. BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION(aStaticMemberFunction)
  56. has_static_member_function_aStaticMemberFunction<T,void (U::Ntype)>::value;
  57. Once again if the nested type U::Ntype does not exist, this leads to a compiler error,
  58. so let's try our alternative.
  59. Second using `BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION` using our specific form we would code:
  60. #include <boost/tti/member_type.hpp>
  61. #include <boost/tti/has_static_member_function.hpp>
  62. BOOST_TTI_HAS_MEMBER_TYPE(Ntype)
  63. BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION(aStaticMemberFunction)
  64. typedef typename has_member_type_Ntype<U>::type OurType;
  65. has_static_member_function_aStaticMemberFunction<T,void,boost::mpl::vector<OurType> >::value;
  66. If the nested type U::Ntype does exist and T does have a member function
  67. whose signature is `void aMemberFunction(U::Ntype)` our 'value' is true,
  68. otherwise it is false. We will never get a compiler error in this case.
  69. [endsect]