optional.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef BOOST_CONTRACT_DETAIL_OPTIONAL_HPP_
  2. #define BOOST_CONTRACT_DETAIL_OPTIONAL_HPP_
  3. // Copyright (C) 2008-2018 Lorenzo Caminiti
  4. // Distributed under the Boost Software License, Version 1.0 (see accompanying
  5. // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
  6. // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
  7. #include <boost/optional.hpp>
  8. #include <boost/type_traits/remove_reference.hpp>
  9. #include <boost/type_traits/integral_constant.hpp>
  10. namespace boost { namespace contract { namespace detail {
  11. template<typename T>
  12. struct is_optional : boost::false_type {};
  13. template<typename T>
  14. struct is_optional<boost::optional<T> > : boost::true_type {};
  15. template<typename T>
  16. struct optional_value_type { typedef T type; };
  17. template<typename T>
  18. struct optional_value_type<boost::optional<T> > { typedef T type; };
  19. template<typename T>
  20. struct remove_value_reference_if_optional { typedef T type; };
  21. template<typename T>
  22. struct remove_value_reference_if_optional<boost::optional<T> >
  23. { typedef typename boost::remove_reference<T>::type type; };
  24. template<typename T>
  25. T& optional_get(T& x) { return x; }
  26. template<typename T>
  27. T& optional_get(boost::optional<T>& x) { return x.get(); }
  28. template<typename T>
  29. T& optional_get(boost::optional<T&>& x) { return x.get(); }
  30. } } } // namespace
  31. #endif // #include guard