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