From 77341c566e568c7781d7cc7a83684056d7f74908 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Fri, 13 Dec 2019 06:49:14 +1100 Subject: Work around MSVC overload resolution issue in save_item/save_pointer (nw) --- src/emu/device.h | 20 +++++++++---------- src/emu/save.h | 61 +++++++++++++++++++++++++++++--------------------------- 2 files changed, 42 insertions(+), 39 deletions(-) diff --git a/src/emu/device.h b/src/emu/device.h index b09bf535ed4..19735d58dbd 100644 --- a/src/emu/device.h +++ b/src/emu/device.h @@ -610,28 +610,28 @@ public: // state saving interfaces template - void ATTR_COLD save_item(ItemType &&value, const char *valname, int index = 0) + void ATTR_COLD save_item(ItemType &value, const char *valname, int index = 0) { assert(m_save); - m_save->save_item(this, name(), tag(), index, std::forward(value), valname); + m_save->save_item(this, name(), tag(), index, value, valname); } - template - void ATTR_COLD save_item(ItemType &&value, ElementType save_manager::array_unwrap >::underlying_type::*element, const char *valname, int index = 0) + template + void ATTR_COLD save_item(ItemType &value, ElementType StructType::*element, const char *valname, int index = 0) { assert(m_save); - m_save->save_item(this, name(), tag(), index, std::forward(value), element, valname); + m_save->save_item(this, name(), tag(), index, value, element, valname); } template - void ATTR_COLD save_pointer(ItemType &&value, const char *valname, u32 count, int index = 0) + void ATTR_COLD save_pointer(ItemType &value, const char *valname, u32 count, int index = 0) { assert(m_save); - m_save->save_pointer(this, name(), tag(), index, std::forward(value), valname, count); + m_save->save_pointer(this, name(), tag(), index, value, valname, count); } - template - void ATTR_COLD save_pointer(ItemType &&value, ElementType save_manager::pointer_unwrap::underlying_type::*element, const char *valname, u32 count, int index = 0) + template + void ATTR_COLD save_pointer(ItemType &value, ElementType StructType::*element, const char *valname, u32 count, int index = 0) { assert(m_save); - m_save->save_pointer(this, name(), tag(), index, std::forward(value), element, valname, count); + m_save->save_pointer(this, name(), tag(), index, value, element, valname, count); } // debugging diff --git a/src/emu/save.h b/src/emu/save.h index 631fd590296..bd20d816d7c 100644 --- a/src/emu/save.h +++ b/src/emu/save.h @@ -75,6 +75,29 @@ class rewinder; class save_manager { + // stuff for working with arrays + template struct array_unwrap + { + using underlying_type = T; + static constexpr std::size_t SAVE_COUNT = 1U; + static constexpr std::size_t SIZE = sizeof(underlying_type); + static underlying_type *ptr(T &value) { return &value; } + }; + template struct array_unwrap + { + using underlying_type = typename array_unwrap::underlying_type; + static constexpr std::size_t SAVE_COUNT = N * array_unwrap::SAVE_COUNT; + static constexpr std::size_t SIZE = sizeof(underlying_type); + static underlying_type *ptr(T (&value)[N]) { return array_unwrap::ptr(value[0]); } + }; + template struct array_unwrap > + { + using underlying_type = typename array_unwrap::underlying_type; + static constexpr std::size_t SAVE_COUNT = N * array_unwrap::SAVE_COUNT; + static constexpr std::size_t SIZE = sizeof(underlying_type); + static underlying_type *ptr(std::array &value) { return array_unwrap::ptr(value[0]); } + }; + // type_checker is a set of templates to identify valid save types template struct type_checker { static constexpr bool is_atom = false; static constexpr bool is_pointer = false; }; template struct type_checker { static constexpr bool is_atom = false; static constexpr bool is_pointer = true; }; @@ -105,29 +128,6 @@ class save_manager friend class rewinder; public: - // stuff for working with arrays - template struct array_unwrap - { - using underlying_type = T; - static constexpr std::size_t SAVE_COUNT = 1U; - static constexpr std::size_t SIZE = sizeof(underlying_type); - static underlying_type *ptr(T &value) { return &value; } - }; - template struct array_unwrap - { - using underlying_type = typename array_unwrap::underlying_type; - static constexpr std::size_t SAVE_COUNT = N * array_unwrap::SAVE_COUNT; - static constexpr std::size_t SIZE = sizeof(underlying_type); - static underlying_type *ptr(T (&value)[N]) { return array_unwrap::ptr(value[0]); } - }; - template struct array_unwrap > - { - using underlying_type = typename array_unwrap::underlying_type; - static constexpr std::size_t SAVE_COUNT = N * array_unwrap::SAVE_COUNT; - static constexpr std::size_t SIZE = sizeof(underlying_type); - static underlying_type *ptr(std::array &value) { return array_unwrap::ptr(value[0]); } - }; - // stuff to allow STRUCT_MEMBER to work with pointers template struct pointer_unwrap { using underlying_type = typename array_unwrap::underlying_type; }; template struct pointer_unwrap { using underlying_type = typename pointer_unwrap >::underlying_type; }; @@ -168,9 +168,10 @@ public: } // templatized wrapper for structure members - template - void save_item(device_t *device, const char *module, const char *tag, int index, ItemType &value, ElementType array_unwrap::underlying_type::*element, const char *valname) + template + void save_item(device_t *device, const char *module, const char *tag, int index, ItemType &value, ElementType StructType::*element, const char *valname) { + static_assert(std::is_base_of::underlying_type>::value, "Called save_item on a non-matching struct member pointer!"); static_assert(!(sizeof(typename array_unwrap::underlying_type) % sizeof(typename array_unwrap::underlying_type)), "Called save_item on an unaligned struct member!"); static_assert(!type_checker::is_pointer, "Called save_item on a struct member pointer!"); static_assert(type_checker::underlying_type>::is_atom, "Called save_item on a non-fundamental type!"); @@ -185,9 +186,10 @@ public: save_memory(device, module, tag, index, valname, array_unwrap::ptr(value[0]), array_unwrap::SIZE, array_unwrap::SAVE_COUNT * count); } - template - void save_pointer(device_t *device, const char *module, const char *tag, int index, ItemType *value, ElementType array_unwrap::underlying_type::*element, const char *valname, u32 count) + template + void save_pointer(device_t *device, const char *module, const char *tag, int index, ItemType *value, ElementType StructType::*element, const char *valname, u32 count) { + static_assert(std::is_base_of::underlying_type>::value, "Called save_pointer on a non-matching struct member pointer!"); static_assert(!(sizeof(typename array_unwrap::underlying_type) % sizeof(typename array_unwrap::underlying_type)), "Called save_pointer on an unaligned struct member!"); static_assert(!type_checker::is_pointer, "Called save_pointer on a struct member pointer!"); static_assert(type_checker::underlying_type>::is_atom, "Called save_pointer on a non-fundamental type!"); @@ -202,9 +204,10 @@ public: save_memory(device, module, tag, index, valname, array_unwrap::ptr(value[0]), array_unwrap::SIZE, array_unwrap::SAVE_COUNT * count); } - template - void save_pointer(device_t *device, const char *module, const char *tag, int index, const std::unique_ptr &value, ElementType array_unwrap::underlying_type::*element, const char *valname, u32 count) + template + void save_pointer(device_t *device, const char *module, const char *tag, int index, const std::unique_ptr &value, ElementType StructType::*element, const char *valname, u32 count) { + static_assert(std::is_base_of::underlying_type>::value, "Called save_pointer on a non-matching struct member pointer!"); static_assert(!(sizeof(typename array_unwrap::underlying_type) % sizeof(typename array_unwrap::underlying_type)), "Called save_pointer on an unaligned struct member!"); static_assert(!type_checker::is_pointer, "Called save_pointer on a struct member pointer!"); static_assert(type_checker::underlying_type>::is_atom, "Called save_pointer on a non-fundamental type!"); -- cgit v1.2.3