is_noncopyable.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. ///////////////////////////////////////////////////////////////////////////////
  2. /// \file is_noncopyable.hpp
  3. /// Utility for detecting when types are non-copyable
  4. //
  5. // Copyright 2008 Eric Niebler. Distributed under the Boost
  6. // Software License, Version 1.0. (See accompanying file
  7. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  8. #ifndef BOOST_PROTO_DETAIL_IS_NONCOPYABLE_HPP_EAN_19_07_2012
  9. #define BOOST_PROTO_DETAIL_IS_NONCOPYABLE_HPP_EAN_19_07_2012
  10. #include <boost/noncopyable.hpp>
  11. #include <boost/mpl/or.hpp>
  12. #include <boost/mpl/bool.hpp>
  13. #include <boost/type_traits/is_base_of.hpp>
  14. #include <boost/type_traits/is_abstract.hpp>
  15. #include <boost/type_traits/is_function.hpp>
  16. #include <boost/proto/proto_fwd.hpp>
  17. namespace boost { namespace proto { namespace detail
  18. {
  19. // All classes derived from std::ios_base have these public nested types,
  20. // and are non-copyable. This is an imperfect test, but it's the best we
  21. // we can do.
  22. template<typename T>
  23. yes_type check_is_iostream(
  24. typename T::failure *
  25. , typename T::Init *
  26. , typename T::fmtflags *
  27. , typename T::iostate *
  28. , typename T::openmode *
  29. , typename T::seekdir *
  30. );
  31. template<typename T>
  32. no_type check_is_iostream(...);
  33. template<typename T>
  34. struct is_iostream
  35. {
  36. static bool const value = sizeof(yes_type) == sizeof(check_is_iostream<T>(0,0,0,0,0,0));
  37. typedef mpl::bool_<value> type;
  38. };
  39. /// INTERNAL ONLY
  40. // This should be a customization point. And it serves the same purpose
  41. // as the is_noncopyable trait in Boost.Foreach.
  42. template<typename T>
  43. struct is_noncopyable
  44. : mpl::or_<
  45. is_function<T>
  46. , is_abstract<T>
  47. , is_iostream<T>
  48. , is_base_of<noncopyable, T>
  49. >
  50. {};
  51. template<typename T, std::size_t N>
  52. struct is_noncopyable<T[N]>
  53. : mpl::true_
  54. {};
  55. }}}
  56. #endif