traits.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2009-2012.
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // See http://www.boost.org/libs/move for documentation.
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11. //! \file
  12. #ifndef BOOST_MOVE_TRAITS_HPP
  13. #define BOOST_MOVE_TRAITS_HPP
  14. #ifndef BOOST_CONFIG_HPP
  15. # include <boost/config.hpp>
  16. #endif
  17. #
  18. #if defined(BOOST_HAS_PRAGMA_ONCE)
  19. # pragma once
  20. #endif
  21. #include <boost/move/detail/config_begin.hpp>
  22. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  23. #include <boost/move/core.hpp>
  24. #endif
  25. #include <boost/move/detail/meta_utils.hpp>
  26. #include <boost/move/detail/type_traits.hpp>
  27. namespace boost {
  28. //! If this trait yields to true
  29. //! (<i>has_trivial_destructor_after_move &lt;T&gt;::value == true</i>)
  30. //! means that if T is used as argument of a move construction/assignment,
  31. //! there is no need to call T's destructor.
  32. //! This optimization tipically is used to improve containers' performance.
  33. //!
  34. //! By default this trait is true if the type has trivial destructor,
  35. //! every class should specialize this trait if it wants to improve performance
  36. //! when inserted in containers.
  37. template <class T>
  38. struct has_trivial_destructor_after_move
  39. : ::boost::move_detail::is_trivially_destructible<T>
  40. {};
  41. //! By default this traits returns
  42. //! <pre>boost::is_nothrow_move_constructible<T>::value && boost::is_nothrow_move_assignable<T>::value </pre>.
  43. //! Classes with non-throwing move constructor
  44. //! and assignment can specialize this trait to obtain some performance improvements.
  45. template <class T>
  46. struct has_nothrow_move
  47. {
  48. static const bool value = boost::move_detail::is_nothrow_move_constructible<T>::value &&
  49. boost::move_detail::is_nothrow_move_assignable<T>::value;
  50. };
  51. namespace move_detail {
  52. template <class T>
  53. struct is_nothrow_move_constructible_or_uncopyable
  54. {
  55. //The standard requires is_nothrow_move_constructible for move_if_noexcept
  56. //but a user (usually in C++03) might specialize has_nothrow_move which includes it
  57. static const bool value = is_nothrow_move_constructible<T>::value ||
  58. has_nothrow_move<T>::value ||
  59. !is_copy_constructible<T>::value;
  60. };
  61. } //move_detail {
  62. } //namespace boost {
  63. #include <boost/move/detail/config_end.hpp>
  64. #endif //#ifndef BOOST_MOVE_TRAITS_HPP