MetaStuff icon indicating copy to clipboard operation
MetaStuff copied to clipboard

C++17?

Open eliasdaler opened this issue 7 years ago • 7 comments

I want to start using C++17 for the following reasons:

  1. Constexpr if - huge one. Less SFINAE - more readable code, less compile time hacks which made my life harder.
  2. 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.

eliasdaler avatar May 24 '18 06:05 eliasdaler

Go for it. C++17 is very benefitial for this project and will be available from most compilers soon.

aggsol avatar May 24 '18 07:05 aggsol

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.

Nightmare82 avatar May 24 '18 08:05 Nightmare82

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

SpeCter avatar May 24 '18 11:05 SpeCter

Yes, I'll test it with these compilers, as I have no doubts about GCC and Clang working fine, but MSVC - who knows... :D

eliasdaler avatar May 24 '18 14:05 eliasdaler

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.

davidgraeff avatar May 28 '18 14:05 davidgraeff

I'd even go for a C++20 implementation, although that might be a step too far.

ninkibah avatar Jun 03 '21 21:06 ninkibah

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!

ninkibah avatar Nov 09 '21 18:11 ninkibah