extract_optional_type.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Boost.Range library
  2. //
  3. // Copyright Arno Schoedl & Neil Groves 2009.
  4. // Use, modification and distribution is subject to the Boost Software
  5. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // For more information, see http://www.boost.org/libs/range/
  9. //
  10. #ifndef BOOST_RANGE_DETAIL_EXTRACT_OPTIONAL_TYPE_HPP_INCLUDED
  11. #define BOOST_RANGE_DETAIL_EXTRACT_OPTIONAL_TYPE_HPP_INCLUDED
  12. #if defined(_MSC_VER)
  13. # pragma once
  14. #endif
  15. #include <boost/config.hpp>
  16. #include <boost/preprocessor/cat.hpp>
  17. #include <boost/mpl/has_xxx.hpp>
  18. #if !defined(BOOST_MPL_CFG_NO_HAS_XXX)
  19. // Defines extract_some_typedef<T> which exposes T::some_typedef as
  20. // extract_some_typedef<T>::type if T::some_typedef exists. Otherwise
  21. // extract_some_typedef<T> is empty.
  22. #define BOOST_RANGE_EXTRACT_OPTIONAL_TYPE( a_typedef ) \
  23. BOOST_MPL_HAS_XXX_TRAIT_DEF(a_typedef) \
  24. template< typename C, bool B = BOOST_PP_CAT(has_, a_typedef)<C>::value > \
  25. struct BOOST_PP_CAT(extract_, a_typedef) \
  26. {}; \
  27. template< typename C > \
  28. struct BOOST_PP_CAT(extract_, a_typedef)< C, true > \
  29. { \
  30. typedef BOOST_DEDUCED_TYPENAME C::a_typedef type; \
  31. };
  32. #else
  33. #define BOOST_RANGE_EXTRACT_OPTIONAL_TYPE( a_typedef ) \
  34. template< typename C > \
  35. struct BOOST_PP_CAT(extract_, a_typedef) \
  36. { \
  37. typedef BOOST_DEDUCED_TYPENAME C::a_typedef type; \
  38. };
  39. #endif
  40. #endif // include guard