diff --git a/include/llama/Core.hpp b/include/llama/Core.hpp index 62295c4783..8313da884b 100644 --- a/include/llama/Core.hpp +++ b/include/llama/Core.hpp @@ -482,27 +482,6 @@ namespace llama // the cost of more template instantiations return size; } - - template - constexpr auto offsetOfImplWorkaround() -> std::size_t; - - // recursive formulation to benefit from template instantiation memoization - // this massively improves compilation time when this template is instantiated with a lot of different I - template - inline constexpr std::size_t offsetOfImpl - = offsetOfImplWorkaround(); // FIXME: MSVC fails to compile an IILE here. - - template - inline constexpr std::size_t offsetOfImpl = 0; - - template - constexpr auto offsetOfImplWorkaround() -> std::size_t - { - std::size_t offset = offsetOfImpl + sizeof(boost::mp11::mp_at_c); - if constexpr(Align) - offset = roundUpToMultiple(offset, alignof(boost::mp11::mp_at_c)); - return offset; - } } // namespace internal /// The size of a type list if its elements would be in a normal struct. @@ -522,7 +501,21 @@ namespace llama /// The byte offset of an element in a type list ifs elements would be in a normal struct. template - inline constexpr std::size_t flatOffsetOf = internal::offsetOfImpl; + inline constexpr std::size_t flatOffsetOf = []() constexpr + { + if constexpr(I == 0) + return 0; + else + { + // recursive formulation to benefit from template instantiation memoization + // this massively improves compilation time when this template is instantiated with a lot of different I + std::size_t offset = flatOffsetOf + sizeof(boost::mp11::mp_at_c); + if constexpr(Align) + offset = roundUpToMultiple(offset, alignof(boost::mp11::mp_at_c)); + return offset; + } + } + (); /// The byte offset of an element in a record dimension if it would be a normal struct. /// \tparam RecordDim Record dimension tree. diff --git a/include/llama/VirtualRecord.hpp b/include/llama/VirtualRecord.hpp index b95e46b9c8..e12c0ec3d1 100644 --- a/include/llama/VirtualRecord.hpp +++ b/include/llama/VirtualRecord.hpp @@ -747,32 +747,27 @@ namespace llama { using RecordDim = typename VirtualRecord::AccessibleRecordDim; os << "{"; - // TODO(bgruber): I tried refactoring both branches into one, but MSVC and icpc have troubles with correctly - // discarding the discarded if constexpr branch and not instantiating templates inside them. if constexpr(std::is_array_v) { - constexpr auto size = std::extent_v; - boost::mp11::mp_for_each>( + boost::mp11::mp_for_each>>( [&](auto ic) { constexpr std::size_t i = decltype(ic)::value; - os << '[' << i << ']' << ": " << vr(RecordCoord{}); - if(i + 1 < size) + if(i > 0) os << ", "; + os << '[' << i << ']' << ": " << vr(RecordCoord{}); }); } else { - constexpr auto size = boost::mp11::mp_size::value; - boost::mp11::mp_for_each>( + boost::mp11::mp_for_each>>( [&](auto ic) { constexpr std::size_t i = decltype(ic)::value; - using Field = boost::mp11::mp_at_c; - using Tag = GetFieldTag; - os << structName() << ": " << vr(RecordCoord{}); - if(i + 1 < size) + if(i > 0) os << ", "; + using Field = boost::mp11::mp_at_c; + os << structName>() << ": " << vr(RecordCoord{}); }); } os << "}";