add_member_const.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 <boost/callable_traits/detail/config.hpp>
  7. #ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS
  8. int main(){ return 0; }
  9. #else
  10. //[ add_member_const
  11. #include <type_traits>
  12. #include <boost/callable_traits/add_member_const.hpp>
  13. namespace ct = boost::callable_traits;
  14. struct foo {};
  15. int main() {
  16. {
  17. using pmf = int(foo::*)();
  18. using expect = int(foo::*)() const;
  19. using test = ct::add_member_const_t<pmf>;
  20. static_assert(std::is_same<test, expect>::value, "");
  21. } {
  22. // add_member_const_t doesn't change anything when
  23. // the function type is already const.
  24. using pmf = int(foo::*)() const &&;
  25. using expect = int(foo::*)() const &&;
  26. using test = ct::add_member_const_t<pmf>;
  27. static_assert(std::is_same<test, expect>::value, "");
  28. } {
  29. using pmf = int(foo::*)() volatile &;
  30. using expect = int(foo::*)() const volatile &;
  31. using test = ct::add_member_const_t<pmf>;
  32. static_assert(std::is_same<test, expect>::value, "");
  33. } {
  34. // add_member_const_t can also be used with "abominable"
  35. // function types.
  36. using f = int();
  37. using expect = int() const;
  38. using test = ct::add_member_const_t<f>;
  39. static_assert(std::is_same<test, expect>::value, "");
  40. }
  41. }
  42. //]
  43. #endif //#ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS