get_data.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // (C) Copyright 2005 Matthias Troyer
  2. // Use, modification and distribution is subject to the Boost Software
  3. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org for updates, documentation, and revision history.
  6. #ifndef BOOST_SERIALIZATION_DETAIL_GET_DATA_HPP
  7. #define BOOST_SERIALIZATION_DETAIL_GET_DATA_HPP
  8. // MS compatible compilers support #pragma once
  9. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  10. # pragma once
  11. #endif
  12. #if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)
  13. #define STD _STLP_STD
  14. #else
  15. #define STD std
  16. #endif
  17. #include <vector>
  18. #include <valarray>
  19. namespace boost { namespace serialization { namespace detail {
  20. template <class T, class Allocator>
  21. T* get_data(STD::vector<T,Allocator>& v)
  22. {
  23. return v.empty() ? 0 : &(v[0]);
  24. }
  25. template <class T, class Allocator>
  26. T* get_data(STD::vector<T,Allocator> const & v)
  27. {
  28. return get_data(const_cast<STD::vector<T,Allocator>&>(v));
  29. }
  30. template <class T>
  31. T* get_data(STD::valarray<T>& v)
  32. {
  33. return v.size()==0 ? 0 : &(v[0]);
  34. }
  35. template <class T>
  36. const T* get_data(STD::valarray<T> const& v)
  37. {
  38. return get_data(const_cast<STD::valarray<T>&>(v));
  39. }
  40. } } } //namespace boost::serialization::detail
  41. #endif // BOOST_SERIALIZATION_DETAIL_GET_DATA_HPP