]> git.lyx.org Git - lyx.git/blob - boost/boost/exception/enable_error_info.hpp
update boost to version 1.36
[lyx.git] / boost / boost / exception / enable_error_info.hpp
1 //Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
2
3 //Distributed under the Boost Software License, Version 1.0. (See accompanying
4 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 #ifndef UUID_0C5D492E909711DCB658AD4556D89593
7 #define UUID_0C5D492E909711DCB658AD4556D89593
8
9 #include <boost/exception/exception.hpp>
10 #include <boost/detail/workaround.hpp>
11 #include <boost/config.hpp>
12 #include <stddef.h>
13
14 namespace
15 boost
16     {
17     namespace
18     exception_detail
19         {
20         template <class T>
21         struct
22         error_info_injector:
23             public T,
24             public exception
25             {
26             explicit
27             error_info_injector( T const & x ):
28                 T(x)
29                 {
30                 }
31
32             ~error_info_injector() throw()
33                 {
34                 }
35
36             char const *
37             diagnostic_information() const throw()
38                 {
39                 return boost::exception::_diagnostic_information(T::what());
40                 }
41             };
42
43         struct large_size { char c[256]; };
44         large_size dispatch( exception * );
45
46         struct small_size { };
47         small_size dispatch( void * );
48
49         template <class,size_t>
50         struct enable_error_info_helper;
51
52         template <class T>
53         struct
54         enable_error_info_helper<T,sizeof(large_size)>
55             {
56             typedef T type;
57             };
58
59         template <class T>
60         struct
61         enable_error_info_helper<T,sizeof(small_size)>
62             {
63             typedef error_info_injector<T> type;
64             };
65
66 #if BOOST_WORKAROUND(__BORLANDC__,BOOST_TESTED_AT(0x582))
67         template <class T>
68         struct
69         sizeof_dispatch
70             {
71             BOOST_STATIC_CONSTANT(int, value = sizeof(dispatch((T*)0)) );
72             };
73
74         template <class T>
75         struct
76         enable_error_info_return_type
77             {
78             typedef typename enable_error_info_helper<T,sizeof_dispatch<T>::value>::type type;
79             };
80 #else
81         template <class T>
82         struct
83         enable_error_info_return_type
84             {
85             typedef typename enable_error_info_helper<T,sizeof(dispatch((T*)0))>::type type;
86             };
87 #endif
88         }
89
90     template <class T>
91     inline
92 #if !BOOST_WORKAROUND(__BORLANDC__,BOOST_TESTED_AT(0x582))
93     typename
94 #endif
95     exception_detail::enable_error_info_return_type<T>::type
96     enable_error_info( T const & x )
97         {
98         return
99 #if !BOOST_WORKAROUND(__BORLANDC__,BOOST_TESTED_AT(0x582))
100         typename
101 #endif
102         exception_detail::enable_error_info_return_type<T>::type(x);
103         }
104     }
105
106 #endif