Giter Club home page Giter Club logo

Comments (5)

liuzicheng1987 avatar liuzicheng1987 commented on August 26, 2024 1

This is a bit tricky...we use C++ concepts quite a bit, which is C++ 20 feature. But maybe we can find a workaround using Macros. You are not the first one to request this, to be honest.

from reflect-cpp.

muddessir avatar muddessir commented on August 26, 2024

It would be amazing if it can be used in c++17/c++14 projects. (And the option of disabling exceptions)

Thank you.

from reflect-cpp.

liuzicheng1987 avatar liuzicheng1987 commented on August 26, 2024

As far as the exceptions are concerned, we already have that:

https://github.com/getml/reflect-cpp/blob/main/docs/result.md

from reflect-cpp.

liuzicheng1987 avatar liuzicheng1987 commented on August 26, 2024

Here is the next problem: The way we pass strings as a template parameter is a C++ 20 feature:

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0732r2.pdf

As explained in this proposal, if we did this in C++ 17, we would always have to explicitly pass the string length as well. So instead of:

rfl::Field<std::string, "firstName">

we would have to write

rfl::Field<std::string, "firstName", 9>

which is obviously less elegant. If someone can find a workaround for that, I am very open to ideas.

from reflect-cpp.

Pennywise007 avatar Pennywise007 commented on August 26, 2024

@liuzicheng1987 I am not sure that there will be an elegant solution for C++17, as I understand one of the main features of your library is that macros are not required, I would say to make it compatible with C++17 adding simple macros just to add text will be fine.
I would recommend you to check this, this solution allows add text as a template argument in C++17 without providing an extra length argument. I understand that all this decltype("text"_something) is not elegant, but I would say just create a simple macro, sth like:

#if __cplusplus >= 202002L
#define Name(text) decltype(text##_something)
#else
#define Name(text) text
#endif

And declare field like(only necessary for C++17, but for C++20 also will work):
rfl::Field<std::string, Name("firstName")>

The other problem is that std::is_constructible will be false in C++17 for this case:

struct T {
   int a;
};
static_assert(std::is_constructible_v<T, int>); // false

But it is easy to fix. I am not completely sure but it looks like the rest code should work without big changes in C++17.

from reflect-cpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.