1 | // Copyright (C) 2003, Fernando Luis Cacciola Carballal. |
2 | // Copyright (C) 2014, 2015 Andrzej Krzemienski. |
3 | // |
4 | // Distributed under the Boost Software License, Version 1.0. |
5 | // (See accompanying file LICENSE_1_0.txt or copy at |
6 | // http://www.boost.org/LICENSE_1_0.txt) |
7 | // |
8 | // See http://www.boost.org/libs/optional for documentation. |
9 | // |
10 | // You are welcome to contact the author at: |
11 | // fernando_cacciola@hotmail.com |
12 | // |
13 | #ifndef BOOST_NONE_17SEP2003_HPP |
14 | #define BOOST_NONE_17SEP2003_HPP |
15 | |
16 | #include "boost/config.hpp" |
17 | #include "boost/none_t.hpp" |
18 | |
19 | // NOTE: Borland users have to include this header outside any precompiled headers |
20 | // (bcc<=5.64 cannot include instance data in a precompiled header) |
21 | // -- * To be verified, now that there's no unnamed namespace |
22 | |
23 | namespace boost { |
24 | |
25 | #ifdef BOOST_OPTIONAL_USE_OLD_DEFINITION_OF_NONE |
26 | |
27 | BOOST_INLINE_VARIABLE none_t const none = (static_cast<none_t>(0)) ; |
28 | |
29 | #elif defined BOOST_OPTIONAL_USE_SINGLETON_DEFINITION_OF_NONE |
30 | |
31 | namespace detail { namespace optional_detail { |
32 | |
33 | // the trick here is to make boost::none defined once as a global but in a header file |
34 | template <typename T> |
35 | struct none_instance |
36 | { |
37 | static const T instance; |
38 | }; |
39 | |
40 | template <typename T> |
41 | const T none_instance<T>::instance = T(); // global, but because 'tis a template, no cpp file required |
42 | |
43 | } } // namespace detail::optional_detail |
44 | |
45 | |
46 | namespace { |
47 | // TU-local |
48 | const none_t& none = detail::optional_detail::none_instance<none_t>::instance; |
49 | } |
50 | |
51 | #else |
52 | |
53 | BOOST_INLINE_VARIABLE const none_t none ((none_t::init_tag())); |
54 | |
55 | #endif // older definitions |
56 | |
57 | } // namespace boost |
58 | |
59 | #endif // header guard |
60 | |
61 | |