class_of.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. @Copyright Barrett Adair 2015-2017
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  5. */
  6. #ifndef BOOST_CLBL_TRTS_class_of_HPP
  7. #define BOOST_CLBL_TRTS_class_of_HPP
  8. #include <boost/callable_traits/detail/core.hpp>
  9. namespace boost { namespace callable_traits {
  10. //[ class_of_hpp
  11. /*`
  12. [section:ref_class_of class_of]
  13. [heading Header]
  14. ``#include <boost/callable_traits/class_of.hpp>``
  15. [heading Definition]
  16. */
  17. template<typename T>
  18. using class_of_t = //see below
  19. //<-
  20. detail::try_but_fail_if_invalid<
  21. typename detail::traits<detail::shallow_decay<T>>::class_type,
  22. type_is_not_a_member_pointer>;
  23. namespace detail {
  24. template<typename T, typename = std::false_type>
  25. struct class_of_impl {};
  26. template<typename T>
  27. struct class_of_impl <T, typename std::is_same<
  28. class_of_t<T>, detail::dummy>::type>
  29. {
  30. using type = class_of_t<T>;
  31. };
  32. }
  33. //->
  34. template<typename T>
  35. struct class_of : detail::class_of_impl<T> {};
  36. //<-
  37. }} // namespace boost::callable_traits
  38. //->
  39. /*`
  40. [heading Constraints]
  41. * `T` must be a member pointer
  42. [heading Behavior]
  43. * A substitution failure occurs if the constraints are violated.
  44. * The aliased type is the parent class of the member. In other words, if `T` is expanded to `U C::*`, the aliased type is `C`.
  45. [heading Input/Output Examples]
  46. [table
  47. [[`T`] [`class_of_t<T>`]]
  48. [[`int foo::*`] [`foo`]]
  49. [[`void(foo::* const &)() const`] [`foo`]]
  50. ]
  51. [heading Example Program]
  52. [import ../example/class_of.cpp]
  53. [class_of]
  54. [endsect]
  55. */
  56. //]
  57. #endif // #ifndef BOOST_CLBL_TRTS_class_of_HPP