has_member_qualifiers_simple.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. Copyright Barrett Adair 2016-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. #include <type_traits>
  7. #include <functional>
  8. #include <utility>
  9. #include <boost/callable_traits/has_member_qualifiers.hpp>
  10. #include "test.hpp"
  11. struct foo {};
  12. template<typename T>
  13. void assert_qualified() {
  14. CT_ASSERT( has_member_qualifiers<T>::value);
  15. }
  16. template<typename T>
  17. void assert_unqualified() {
  18. CT_ASSERT(! has_member_qualifiers<T>::value);
  19. }
  20. int main() {
  21. {
  22. using f = void(foo::*)();
  23. using c = void(foo::*)() const;
  24. using v = void(foo::*)() volatile;
  25. using cv = void(foo::*)() const volatile;
  26. assert_unqualified<f>();
  27. assert_qualified<c>();
  28. assert_qualified<v>();
  29. assert_qualified<cv>();
  30. }
  31. {
  32. struct f { int operator()() { return 0; } };
  33. struct c { int operator()() const { return 0; } };
  34. struct v { int operator()() volatile { return 0; } };
  35. struct cv { int operator()() const volatile { return 0; } };
  36. assert_unqualified<f>();
  37. assert_qualified<c>();
  38. assert_qualified<v>();
  39. assert_qualified<cv>();
  40. }
  41. using f_ptr = void(*)();
  42. assert_unqualified<f_ptr>();
  43. assert_unqualified<f_ptr foo::*>();
  44. assert_unqualified<int foo::*>();
  45. assert_unqualified<void(&)()>();
  46. }