Skip to content

User-Defined Types not work with MSVC 2022?! #25

@An0nyMooUS

Description

@An0nyMooUS
namespace example {
    struct Person {
        std::string name;
        std::uint32_t age_years;
        std::uint8_t height_inches;
        std::uint16_t weight_pounds;
        NOP_STRUCTURE(Person, name, age_years, height_inches, weight_pounds);
    };
}  // namespace example

int main(int argc, char** argv) {
    using Writer = nop::StreamWriter<std::stringstream>;
    nop::Serializer<Writer> serializer;

    serializer.Write(example::Person{ "John Doe", 37, 72, 180 });
    serializer.Write(std::vector<example::Person>{
        {"John Doe", 37, 72, 180}, { "Jane Doe", 36, 69, 130 }});

    const std::string data = serializer.writer().stream().str();
    std::cout << "Wrote " << data.size() << " bytes." << std::endl;

    // [write to file]
    std::ofstream saveFile("e.bin", std::ios::binary);
    saveFile.write(data.c_str(), data.size());
    saveFile.flush();
    saveFile.close();

    return 0;
}

MSVC 2022 Result:
Wrote 8 bytes.
image
Warnings

  • warning C4003: not enough arguments for function-like macro invocation '_NOP_FIRST_ARG'
  • warning C4003: not enough arguments for function-like macro invocation '_NOP_REST_ARG'

CLANG LLVM Result:
Wrote 50 bytes.
image

why this not working with MSVC 2022?!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions