param_type.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // (C) Copyright Tobias Schwinger
  2. //
  3. // Use modification and distribution are subject to the boost Software License,
  4. // Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt).
  5. //------------------------------------------------------------------------------
  6. // Metafunction to compute optimal parameter type for argument forwarding.
  7. // This header is not an FT example in itself -- it's used by some of them to
  8. // optimize argument forwarding.
  9. //
  10. // For more details see 'fast_mem_fn.hpp' in this directory or the documentation
  11. // of the CallTraits utility [1].
  12. //
  13. //
  14. // References
  15. // ==========
  16. //
  17. // [1] http://www.boost.org/libs/utility/call_traits.htm
  18. #ifndef BOOST_UTILITY_PARAM_TYPE_HPP_INCLUDED
  19. #define BOOST_UTILITY_PARAM_TYPE_HPP_INCLUDED
  20. #include <boost/config.hpp>
  21. #include <boost/type_traits/add_const.hpp>
  22. #include <boost/type_traits/add_reference.hpp>
  23. #include <boost/mpl/eval_if.hpp>
  24. #include <boost/mpl/identity.hpp>
  25. #include <boost/mpl/aux_/lambda_support.hpp>
  26. // #include <boost/type_traits/detail/template_arity_spec.hpp>
  27. // namespace boost
  28. namespace example
  29. {
  30. namespace mpl = boost::mpl;
  31. // namespace utility
  32. // {
  33. namespace param_type_detail
  34. {
  35. template<typename T>
  36. struct by_ref_cond
  37. {
  38. typedef by_ref_cond type;
  39. BOOST_STATIC_CONSTANT(bool,value = sizeof(void*) < sizeof(T));
  40. };
  41. template<typename T>
  42. struct add_ref_to_const
  43. : boost::add_reference< typename boost::add_const<T>::type >
  44. { };
  45. }
  46. template<typename T>
  47. struct param_type
  48. : mpl::eval_if< param_type_detail::by_ref_cond<T>
  49. , param_type_detail::add_ref_to_const<T>, mpl::identity<T> >
  50. {
  51. BOOST_MPL_AUX_LAMBDA_SUPPORT(1,param_type,(T))
  52. };
  53. // }
  54. // BOOST_TT_AUX_TEMPLATE_ARITY_SPEC(1,utility::param_type)
  55. }
  56. #endif