relaxed.hpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Boost.TypeErasure library
  2. //
  3. // Copyright 2011 Steven Watanabe
  4. //
  5. // Distributed under the Boost Software License Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // $Id$
  10. #ifndef BOOST_TYPE_ERASURE_RELAXED_HPP_INCLUDED
  11. #define BOOST_TYPE_ERASURE_RELAXED_HPP_INCLUDED
  12. #include <boost/mpl/vector.hpp>
  13. #include <boost/mpl/bool.hpp>
  14. #include <boost/mpl/is_sequence.hpp>
  15. #include <boost/mpl/find_if.hpp>
  16. #include <boost/mpl/not.hpp>
  17. #include <boost/mpl/end.hpp>
  18. #include <boost/type_traits/is_same.hpp>
  19. namespace boost {
  20. namespace type_erasure {
  21. template<class T>
  22. struct is_relaxed;
  23. namespace detail {
  24. template<class T>
  25. struct is_relaxed_impl :
  26. ::boost::mpl::not_<
  27. typename ::boost::is_same<
  28. typename ::boost::mpl::find_if<
  29. T,
  30. ::boost::type_erasure::is_relaxed< ::boost::mpl::_1>
  31. >::type,
  32. typename ::boost::mpl::end<T>::type
  33. >::type
  34. >::type
  35. {};
  36. }
  37. /**
  38. * This special concept enables various useful default behavior that
  39. * makes @ref any act like an ordinary object. By default @ref any
  40. * forwards all operations to the underlying type, and provides only
  41. * the operations that are specified in its @c Concept.
  42. *
  43. * In detail, @ref relaxed enables the following:
  44. * - A raw value can be assigned to an @ref any. This will replace
  45. * the value stored by the @ref any. (But note that if @ref assignable
  46. * is present, it takes priority.)
  47. * - assignment of @ref any uses the constructor if it can't
  48. * use @ref assignable (either because @ref assignable is missing,
  49. * or because the stored types do not match).
  50. * - default construction of @ref any is allowed and creates a null any.
  51. * - @ref equality_comparable "equality_comparable": If the types do not
  52. * match, it will return false.
  53. * - @ref less_than_comparable "less_than_comparable": If the types do not
  54. * match, the ordering will be according to
  55. * @c std::type_info::before.
  56. * - if the arguments to any other function do not match, it will throw
  57. * a @ref bad_function_call exception instead of having undefined
  58. * behavior.
  59. */
  60. struct relaxed : ::boost::mpl::vector0<> {};
  61. /**
  62. * A metafunction indicating whether @c Concept
  63. * includes @ref relaxed.
  64. */
  65. template<class Concept>
  66. struct is_relaxed :
  67. ::boost::mpl::eval_if< ::boost::mpl::is_sequence<Concept>,
  68. ::boost::type_erasure::detail::is_relaxed_impl<Concept>,
  69. ::boost::mpl::false_
  70. >::type
  71. {};
  72. /** INTERNAL ONLY */
  73. template<>
  74. struct is_relaxed< ::boost::type_erasure::relaxed> :
  75. ::boost::mpl::true_
  76. {};
  77. }
  78. }
  79. #endif