From d680d1f81e0233024de2742a7e8ab08bd87ec94a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 27 Jan 2017 02:48:46 -0500 Subject: [PATCH] MMIO: Get rid of a TODO regarding tuples --- Source/Core/Core/HW/MMIO.h | 40 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/Source/Core/Core/HW/MMIO.h b/Source/Core/Core/HW/MMIO.h index 9584fac332..8ee706a1ab 100644 --- a/Source/Core/Core/HW/MMIO.h +++ b/Source/Core/Core/HW/MMIO.h @@ -6,6 +6,7 @@ #include #include +#include #include #include "Common/Assert.h" @@ -177,45 +178,30 @@ private: HandlerArray::Write m_write_handlers32; // Getter functions for the handler arrays. - // - // TODO: - // It would be desirable to clean these methods up using tuples, i.e. doing something like - // - // auto handlers = std::tie(m_read_handlers8, m_read_handlers16, m_read_handlers32); - // return std::get(handlers)[index]; - // - // However, we cannot use this currently because of a compiler bug in clang, presumably related - // to http://llvm.org/bugs/show_bug.cgi?id=18345, due to which the above code makes the compiler - // exceed the template recursion depth. - // As a workaround, we cast all handlers to the requested one's type. This cast will - // compile to a NOP for the returned member variable, but it's necessary to get this - // code to compile at all. template ReadHandler& GetReadHandler(size_t index) { - static_assert(std::is_same::value || std::is_same::value || - std::is_same::value, + static_assert(std::is_same() || std::is_same() || + std::is_same(), "Invalid unit used"); + + auto handlers = std::tie(m_read_handlers8, m_read_handlers16, m_read_handlers32); + using ArrayType = typename HandlerArray::Read; - ArrayType& handler = *(std::is_same::value ? - (ArrayType*)&m_read_handlers8 : - std::is_same::value ? (ArrayType*)&m_read_handlers16 : - (ArrayType*)&m_read_handlers32); - return handler[index]; + return std::get(handlers)[index]; } template WriteHandler& GetWriteHandler(size_t index) { - static_assert(std::is_same::value || std::is_same::value || - std::is_same::value, + static_assert(std::is_same() || std::is_same() || + std::is_same(), "Invalid unit used"); + + auto handlers = std::tie(m_write_handlers8, m_write_handlers16, m_write_handlers32); + using ArrayType = typename HandlerArray::Write; - ArrayType& handler = *(std::is_same::value ? - (ArrayType*)&m_write_handlers8 : - std::is_same::value ? (ArrayType*)&m_write_handlers16 : - (ArrayType*)&m_write_handlers32); - return handler[index]; + return std::get(handlers)[index]; } };