pfto.hpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef BOOST_SERIALIZATION_PFTO_HPP
  2. #define BOOST_SERIALIZATION_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. namespace serialization {
  37. template<class T>
  38. struct pfto_wrapper {
  39. const T & t;
  40. operator const T & (){
  41. return t;
  42. }
  43. pfto_wrapper (const T & rhs) : t(rhs) {}
  44. };
  45. template<class T>
  46. pfto_wrapper<T> make_pfto_wrapper(const T & t, BOOST_PFTO int){
  47. return pfto_wrapper<T>(t);
  48. }
  49. template<class T>
  50. pfto_wrapper<T> make_pfto_wrapper(const pfto_wrapper<T> & t, int){
  51. return t;
  52. }
  53. } // namespace serialization
  54. } // namespace boost
  55. #ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
  56. #define BOOST_PFTO_WRAPPER(T) \
  57. boost::serialization::pfto_wrapper<T>
  58. #define BOOST_MAKE_PFTO_WRAPPER(t) \
  59. boost::serialization::make_pfto_wrapper(t, 0)
  60. #else
  61. #define BOOST_PFTO_WRAPPER(T) T
  62. #define BOOST_MAKE_PFTO_WRAPPER(t) t
  63. #endif
  64. #endif // BOOST_SERIALIZATION_PFTO_HPP