diff --git a/.github/workflows/msvc.yml b/.github/workflows/msvc_2019.yml similarity index 98% rename from .github/workflows/msvc.yml rename to .github/workflows/msvc_2019.yml index 9dbea3df26..785b983b3b 100644 --- a/.github/workflows/msvc.yml +++ b/.github/workflows/msvc_2019.yml @@ -1,4 +1,4 @@ -name: msvc +name: msvc_2019 on: push: diff --git a/.github/workflows/msvc_cpm.yml b/.github/workflows/msvc_2022.yml similarity index 65% rename from .github/workflows/msvc_cpm.yml rename to .github/workflows/msvc_2022.yml index 1d7cc36a19..0458a9ba2a 100644 --- a/.github/workflows/msvc_cpm.yml +++ b/.github/workflows/msvc_2022.yml @@ -1,4 +1,4 @@ -name: msvc_cpm +name: msvc_2022 on: push: @@ -17,14 +17,13 @@ env: jobs: build: - runs-on: windows-2019 + runs-on: windows-2022 steps: - uses: actions/checkout@v3 - # using specific windows SDK to address this issue: https://stackoverflow.com/questions/65402366/c5105-and-other-compiler-warnings-when-building-with-github-actions-winsdk-10 - name: Configure CMake - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_SYSTEM_VERSION="10.0.22621.0" + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} - name: Build run: cmake --build build --config ${{env.BUILD_TYPE}} -j 2 diff --git a/include/glaze/api/name.hpp b/include/glaze/api/name.hpp index baf86ddab9..87dec7a121 100644 --- a/include/glaze/api/name.hpp +++ b/include/glaze/api/name.hpp @@ -14,40 +14,48 @@ namespace glz { namespace detail { - inline constexpr auto total_length(const auto& strs) noexcept { +#ifdef _MSC_VER + // Workaround for problems with MSVC and passing refrences to stringviews as template params + struct string_view_wrapper + { + const char* start{}; size_t n{}; - for_each>>([&](auto I) { n += std::get(strs).size(); }); - return n; - } - + constexpr string_view_wrapper(std::string_view sv) : start(sv.data()), n(sv.size()) {} + constexpr auto data() const { return start; } + constexpr auto begin() const { return data(); } + constexpr auto end() const { return data() + n; } + constexpr auto size() const { return n; } + }; + template +#else template +#endif struct join { // Join all strings into a single std::array of chars static constexpr auto impl() noexcept { - // This local copy to a tuple and avoiding of parameter pack expansion is needed to avoid MSVC internal compiler errors - constexpr auto strs_tuple = std::make_tuple(Strs...); - //constexpr size_t len = (Strs.size() + ... + 0); - constexpr size_t len = total_length(strs_tuple); + // This local copy to a tuple and avoiding of parameter pack expansion is needed to avoid MSVC internal + // compiler errors + constexpr size_t len = (Strs.size() + ... + 0); std::array arr{}; auto append = [i = 0, &arr](const auto& s) mutable { for (auto c : s) arr[i++] = c; }; - - for_each([&](auto I) { append(std::get(strs_tuple)); - }); - - //(append(Strs), ...); + (append(Strs), ...); arr[len] = 0; return arr; } - - static constexpr auto arr = impl(); // Give the joined string static storage - static constexpr std::string_view value {arr.data(), arr.size() - 1}; + + static constexpr auto arr = impl(); // Give the joined string static storage + static constexpr std::string_view value{arr.data(), arr.size() - 1}; }; - // Helper to get the value out +// Helper to get the value out +#ifdef _MSC_VER + template +#else template +#endif static constexpr auto join_v = join::value; } diff --git a/include/glaze/binary/write.hpp b/include/glaze/binary/write.hpp index 40a2788352..1e3273bb3f 100644 --- a/include/glaze/binary/write.hpp +++ b/include/glaze/binary/write.hpp @@ -16,7 +16,7 @@ namespace glz { namespace detail - { + { template struct to_binary {}; @@ -29,7 +29,7 @@ namespace glz return to_binary>::template op( std::forward(value), std::forward(b)); } - + template static auto op(T&& value, B&& b, IX&& ix) { @@ -37,7 +37,7 @@ namespace glz std::forward(value), std::forward(b), std::forward(ix)); } }; - + template requires (std::same_as || std::same_as::reference> || std::same_as::const_reference>) struct to_binary final @@ -61,13 +61,13 @@ namespace glz static auto op(auto&& /*value*/, Args&&... args) noexcept { return error{}; } }; - + template auto dump_type(auto&& value, Args&&... args) noexcept { return dump(std::as_bytes(std::span{ &value, 1 }), std::forward(args)...); } - + template [[nodiscard]] auto dump_int(Args&&... args) noexcept { @@ -92,7 +92,7 @@ namespace glz "size not supported"); } } - + template [[nodiscard]] auto dump_int(size_t i, Args&&... args) noexcept(Opts.no_except) { @@ -117,7 +117,7 @@ namespace glz } } } - + template requires num_t || char_t || glaze_enum_t struct to_binary final @@ -128,7 +128,7 @@ namespace glz return dump_type(value, std::forward(args)...); } }; - + template struct to_binary final { @@ -139,7 +139,7 @@ namespace glz dump(std::as_bytes(std::span{ value.data(), value.size() }), std::forward(args)...); } }; - + template struct to_binary final { @@ -154,7 +154,7 @@ namespace glz } } }; - + template struct to_binary final { @@ -168,7 +168,7 @@ namespace glz } } }; - + template struct to_binary final { @@ -184,7 +184,7 @@ namespace glz } } }; - + template requires glaze_object_t struct to_binary final @@ -195,7 +195,7 @@ namespace glz using V = std::decay_t; static constexpr auto N = std::tuple_size_v>; dump_int(std::forward(args)...); // even though N is known at compile time in this case, it is not known for partial cases, so we still use a compressed integer - + for_each([&](auto I) { static constexpr auto item = std::get(meta_v); dump_int(I, std::forward(args)...); // dump the known key as an integer @@ -224,19 +224,19 @@ namespace glz } }; } - + template inline auto write_binary(T&& value, Buffer&& buffer) { return write(std::forward(value), std::forward(buffer)); } - + template inline auto write_binary(T&& value) { std::string buffer{}; write(std::forward(value), buffer); return buffer; } - + template requires nano::ranges::input_range && (sizeof(nano::ranges::range_value_t) == sizeof(char)) inline auto write(T&& value, Buffer& buffer) noexcept @@ -260,9 +260,11 @@ namespace glz if constexpr (detail::glaze_object_t>) { static constexpr auto key_to_int = detail::make_key_int_map(); glz::for_each([&](auto I) { - static constexpr auto group = []() { - return std::get(groups); - }(); // MSVC internal compiler error workaround + using index_t = decltype(I); + using group_t = std::tuple_element_t; + static constexpr auto group = [](index_t Index) constexpr -> group_t { + return std::get(groups); + }({}); // MSVC internal compiler error workaround static constexpr auto key = std::get<0>(group); static constexpr auto sub_partial = std::get<1>(group); static constexpr auto frozen_map = detail::make_map(); @@ -298,12 +300,12 @@ namespace glz else { throw std::runtime_error( "Invalid key for map when writing out partial message"); - } + } }); } } } - + template inline auto write_binary(T&& value, Buffer&& buffer) { return write(std::forward(value), std::forward(buffer));