none.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. #include "boost/config.hpp"
  16. #include "boost/none_t.hpp"
  17. // NOTE: Borland users have to include this header outside any precompiled headers
  18. // (bcc<=5.64 cannot include instance data in a precompiled header)
  19. // -- * To be verified, now that there's no unnamed namespace
  20. namespace boost {
  21. #ifdef BOOST_OPTIONAL_USE_OLD_DEFINITION_OF_NONE
  22. BOOST_INLINE_VARIABLE none_t BOOST_CONSTEXPR_OR_CONST none = (static_cast<none_t>(0)) ;
  23. #elif defined BOOST_OPTIONAL_USE_SINGLETON_DEFINITION_OF_NONE
  24. namespace detail { namespace optional_detail {
  25. // the trick here is to make boost::none defined once as a global but in a header file
  26. template <typename T>
  27. struct none_instance
  28. {
  29. static const T instance;
  30. };
  31. template <typename T>
  32. const T none_instance<T>::instance = T(); // global, but because 'tis a template, no cpp file required
  33. } } // namespace detail::optional_detail
  34. namespace {
  35. // TU-local
  36. const none_t& none = detail::optional_detail::none_instance<none_t>::instance;
  37. }
  38. #else
  39. BOOST_INLINE_VARIABLE BOOST_CONSTEXPR_OR_CONST none_t none ((none_t::init_tag()));
  40. #endif // older definitions
  41. } // namespace boost
  42. #endif // header guard