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