archive_constructed.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* Copyright 2023 Joaquin M Lopez Munoz.
  2. * Distributed under the Boost Software License, Version 1.0.
  3. * (See accompanying file LICENSE_1_0.txt or copy at
  4. * http://www.boost.org/LICENSE_1_0.txt)
  5. *
  6. * See https://www.boost.org/libs/unordered for library home page.
  7. */
  8. #ifndef BOOST_UNORDERED_DETAIL_ARCHIVE_CONSTRUCTED_HPP
  9. #define BOOST_UNORDERED_DETAIL_ARCHIVE_CONSTRUCTED_HPP
  10. #include <boost/unordered/detail/opt_storage.hpp>
  11. #include <boost/config.hpp>
  12. #include <boost/core/no_exceptions_support.hpp>
  13. #include <boost/core/noncopyable.hpp>
  14. #include <boost/core/serialization.hpp>
  15. namespace boost{
  16. namespace unordered{
  17. namespace detail{
  18. /* constructs a stack-based object from a serialization archive */
  19. template<typename T>
  20. struct archive_constructed:private noncopyable
  21. {
  22. template<class Archive>
  23. archive_constructed(const char* name,Archive& ar,unsigned int version)
  24. {
  25. core::load_construct_data_adl(ar,std::addressof(get()),version);
  26. BOOST_TRY{
  27. ar>>core::make_nvp(name,get());
  28. }
  29. BOOST_CATCH(...){
  30. get().~T();
  31. BOOST_RETHROW;
  32. }
  33. BOOST_CATCH_END
  34. }
  35. ~archive_constructed()
  36. {
  37. get().~T();
  38. }
  39. #if defined(BOOST_GCC)&&(BOOST_GCC>=4*10000+6*100)
  40. #define BOOST_UNORDERED_IGNORE_WSTRICT_ALIASING
  41. #endif
  42. #if defined(BOOST_UNORDERED_IGNORE_WSTRICT_ALIASING)
  43. #pragma GCC diagnostic push
  44. #pragma GCC diagnostic ignored "-Wstrict-aliasing"
  45. #endif
  46. T& get(){return *space.address();}
  47. #if defined(BOOST_UNORDERED_IGNORE_WSTRICT_ALIASING)
  48. #pragma GCC diagnostic pop
  49. #undef BOOST_UNORDERED_IGNORE_WSTRICT_ALIASING
  50. #endif
  51. private:
  52. opt_storage<T> space;
  53. };
  54. } /* namespace detail */
  55. } /* namespace unordered */
  56. } /* namespace boost */
  57. #endif