MetaStuff
MetaStuff copied to clipboard
C++17?
I want to start using C++17 for the following reasons:
- Constexpr if - huge one. Less SFINAE - more readable code, less compile time hacks which made my life harder.
- Fold expressions
What do you think? Should I go with it? At least, here's an experimental branch with C++17 stuff in it, so you'll can see if your compiles supports all the things that I'll be using. If it doesn't work well - it won't be merged into master.
Go for it. C++17 is very benefitial for this project and will be available from most compilers soon.
I’d definitely go with c++ 17. I’m using it for a game engine written using c++ 17 and I think the features you mentioned would make MetaStuff clearly better.
As long as it works with the 3 major compilers(msvc,gcc,clang imho), I don't see any problems with it. If not, well I would probably go with it anyway xD
Yes, I'll test it with these compilers, as I have no doubts about GCC and Clang working fine, but MSVC - who knows... :D
Hm. Actually embedded c++ programming benefits from libraries like this as well. Unfortunately it is not unusual for those toolchains to lack bind the state of the art by about 4 years. I would consider this as well and stick to c++14 for a while.
I'd even go for a C++20 implementation, although that might be a step too far.
Elias, here's my C++20 version: https://github.com/ninkibah/MetaStuff/tree/cpp20
Most of it is C++17. The main difference is that I added macros to make it simple to define the registerMembers code. For example, the Person class can be registered like so:
METASTUFF_DEFINE_MEMBERS(Person, Age, Name, salary, favouriteMovies)
MovieInfo is simpler, but can be registered like so:
METASTUFF_DEFINE_MEMBERS(MovieInfo, name, rating)
The METASTUFF_DEFINE_MEMBERS macro takes the class name as the first argument, followed by the members that you want to register. The code uses if constexpr plus some macro trickery to detect if, for example, Person::Age is a public data member or if Person::getAge() and Person::setAge(int) exists. Based on what is available, it builds the appropriate member registration object!
It's obviously not very clean, and I find working with variadic macros incredibly difficult!