pfto.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef BOOST_PFTO_HPP
  2. #define BOOST_PFTO_HPP
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  5. # pragma once
  6. #endif
  7. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  8. // pfto.hpp: workarounds for compilers which have problems supporting
  9. // Partial Function Template Ordering (PFTO).
  10. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  11. // Use, modification and distribution is subject to the Boost Software
  12. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. // See http://www.boost.org/libs/serialization for updates, documentation, and revision history.
  15. // PFTO version is used to specify the last argument of certain functions
  16. // Function it is used to support compilers that fail to support correct Partial
  17. // Template Ordering
  18. #include <boost/config.hpp>
  19. // some compilers can use an exta argument and use function overloading
  20. // to choose desired function. This extra argument is long in the default
  21. // function implementation and int for the rest. The function is called
  22. // with an int argument. This first attempts to match functions with an
  23. // int argument before the default one (with a long argument). This is
  24. // known to function with VC 6.0. On other compilers this fails (Borland)
  25. // or causes other problems (GCC). note: this
  26. #if defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
  27. #define BOOST_PFTO long
  28. #else
  29. #define BOOST_PFTO
  30. #endif
  31. // here's another approach. Rather than use a default function - make sure
  32. // there is no default at all by requiring that all function invocations
  33. // have a "wrapped" argument type. This solves a problem with VC 6.0
  34. // (and perhaps others) while implementing templated constructors.
  35. namespace boost {
  36. template<class T>
  37. struct pfto_wrapper {
  38. const T & t;
  39. operator const T & (){
  40. return t;
  41. }
  42. pfto_wrapper (const T & rhs) : t(rhs) {}
  43. };
  44. template<class T>
  45. pfto_wrapper<T> make_pfto_wrapper(const T & t, BOOST_PFTO int){
  46. return pfto_wrapper<T>(t);
  47. }
  48. template<class T>
  49. pfto_wrapper<T> make_pfto_wrapper(const pfto_wrapper<T> & t, int){
  50. return t;
  51. }
  52. } // namespace boost
  53. #ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
  54. #define BOOST_PFTO_WRAPPER(T) boost::pfto_wrapper<T>
  55. #define BOOST_MAKE_PFTO_WRAPPER(t) boost::make_pfto_wrapper(t, 0)
  56. #else
  57. #define BOOST_PFTO_WRAPPER(T) T
  58. #define BOOST_MAKE_PFTO_WRAPPER(t) t
  59. #endif
  60. #endif // BOOST_PFTO_HPP