bool_trait_def.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
  2. // (C) Copyright 2003-2007 Jonathan Turkanis
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
  5. // See http://www.boost.org/libs/iostreams for documentation.
  6. #ifndef BOOST_IOSTREAMS_DETAIL_BOOL_TRAIT_DEF_HPP_INCLUDED
  7. #define BOOST_IOSTREAMS_DETAIL_BOOL_TRAIT_DEF_HPP_INCLUDED
  8. #include <boost/config.hpp> // BOOST_STATIC_CONSTANT.
  9. #include <boost/iostreams/detail/template_params.hpp>
  10. #include <boost/mpl/aux_/lambda_support.hpp>
  11. #include <boost/mpl/bool.hpp>
  12. #include <boost/preprocessor/cat.hpp>
  13. #include <boost/preprocessor/repetition/enum_params.hpp>
  14. #include <boost/type_traits/detail/yes_no_type.hpp>
  15. //
  16. // Macro name: BOOST_IOSTREAMS_BOOL_TRAIT_DEF
  17. // Description: Used to generate the traits classes is_istream, is_ostream,
  18. // etc.
  19. //
  20. #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
  21. # define BOOST_IOSTREAMS_TRAIT_NAMESPACE(trait)
  22. #else
  23. # define BOOST_IOSTREAMS_TRAIT_NAMESPACE(trait) BOOST_PP_CAT(trait, _impl_)::
  24. #endif
  25. #define BOOST_IOSTREAMS_BOOL_TRAIT_DEF(trait, type, arity) \
  26. namespace BOOST_PP_CAT(trait, _impl_) { \
  27. BOOST_IOSTREAMS_TEMPLATE_PARAMS(arity, T) \
  28. type_traits::yes_type helper \
  29. (const volatile type BOOST_IOSTREAMS_TEMPLATE_ARGS(arity, T)*); \
  30. type_traits::no_type helper(...); \
  31. template<typename T> \
  32. struct impl { \
  33. BOOST_STATIC_CONSTANT(bool, value = \
  34. (sizeof(BOOST_IOSTREAMS_TRAIT_NAMESPACE(trait) \
  35. helper(static_cast<T*>(0))) == \
  36. sizeof(type_traits::yes_type))); \
  37. }; \
  38. } \
  39. template<typename T> \
  40. struct trait \
  41. : mpl::bool_<BOOST_PP_CAT(trait, _impl_)::impl<T>::value> \
  42. { BOOST_MPL_AUX_LAMBDA_SUPPORT(1, trait, (T)) }; \
  43. /**/
  44. #endif // #ifndef BOOST_IOSTREAMS_DETAIL_BOOL_TRAIT_DEF_HPP_INCLUDED