Comments (5)
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.
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.
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.
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.
@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)
- conda-forge package HOT 2
- Q: deserializing/serializing complex XML documents? HOT 6
- Reflector - separate into read and write? HOT 4
- Bug: build system assumes compiler has or is GNU-like front-end HOT 3
- Bug: number of fields in a struct is limited to 100; consider removing limitation? HOT 6
- Reflector + rfl::Flatten in ReflType HOT 2
- support for custom types HOT 2
- Compile error with structures containing bitfields HOT 1
- Can I write to buffer? HOT 1
- TaggedUnions compilation error HOT 4
- Default value of std::optional HOT 2
- Number systems support HOT 3
- SEH exception HOT 6
- std::filesystem::path support HOT 2
- inconsistent treatment of unexpected data formats / feature request DefaultIfMissing HOT 1
- Serialize tall class fails at compilation HOT 4
- RFE: Support for inclusion on Compiler Explorer HOT 4
- undefined reference to `rfl::Generic::~Generic()' HOT 4
- Stripping field name from union HOT 1
- error: implicit instantiation of undefined template 'std::tuple_size<rfl::Tuple<rfl::Field<...>>>' after #160 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reflect-cpp.