function_type.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*<-
  2. Copyright (c) 2016 Barrett Adair
  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_ABOMINABLE_FUNCTIONS
  8. int main(){ return 0; }
  9. #else
  10. //[ function_type
  11. #include <type_traits>
  12. #include <boost/callable_traits.hpp>
  13. namespace ct = boost::callable_traits;
  14. template<typename T>
  15. void test(){
  16. // this example shows how boost::callable_traits::function_type_t
  17. // bevaves consistently for many different types
  18. using type = ct::function_type_t<T>;
  19. using expect = void(int, float&, const char*);
  20. static_assert(std::is_same<expect, type>{}, "");
  21. }
  22. int main() {
  23. auto lamda = [](int, float&, const char*){};
  24. using lam = decltype(lamda);
  25. test<lam>();
  26. using function_ptr = void(*)(int, float&, const char*);
  27. test<function_ptr>();
  28. using function_ref = void(&)(int, float&, const char*);
  29. test<function_ref>();
  30. using function = void(int, float&, const char*);
  31. test<function>();
  32. using abominable = void(int, float&, const char*) const;
  33. test<abominable>();
  34. }
  35. //]
  36. #endif //#ifdef BOOST_CLBL_TRTS_DISABLE_ABOMINABLE_FUNCTIONS