News for hackers. Stuff that matters.
Re:Plywood: A New Cross-Platform Open Source C++ Framework by pjmlp on Tuesday May 26, 2020 @10:49AM (#23311854)
It is a big pain when you need to implement stuff like serialization or data type mappers for stuff like RPC or database access.

However with template metaprogramming and constexpr if there is already quite something when can do into supporting it, today, specially with C++20.

Post C++20, there are ongoing plans to have support for static reflection at compile time, and metaclasses.

Microsoft demoed the current state of their VC++ prototype at Virtual C++2020 days.

"Dynamic Polymorphism with Metaclasses and Code Injection"

https://www.youtube.com/watch?v=drt3yXI-fqk

Re:Plywood: A New Cross-Platform Open Source C++ Framework by badsectoracula on Tuesday May 26, 2020 @11:46AM (#23312600)
Strictly speaking, you can do it without that stuff, here are some snippets of a test i was doing in Borland C++ Builder 1 (from 1996, that is pre-C++98) a few years ago [0] (not using any of BCB's C++ extensions) which end up with this [1] (it is a bunch of controls thrown in a form mainly to test stuff, but the interesting bit is the property editor at the right).

If you do not mind relying a bit too hard on the preprocessor you can also do it in plain C [2] (i mean, the C++ approach still relies on it a lot, but the C one goes all the way :-P).

A game engine (for a big published game, not my own stuff) i worked on at the past used this approach (the C++ one) heavily and i think it is also quite common in some frameworks.

Though personally outside of experimentation i just use Free Pascal which provides the functionality as a core feature of the language (and next version will allow attaching arbitrary attributes to properties, which addresses my "i'd like to have a description for this property for the editor without writing a GetPropertyDescription method" wish :-P).

[0] https://pastebin.com/eCYs1tv8

[1] https://i.imgur.com/Ry5114y.png

[2] https://pastebin.com/8udWrNcv

Re:Plywood: A New Cross-Platform Open Source C++ Framework by pjmlp on Tuesday May 26, 2020 @12:46PM (#23313366)
Agreed, but that is why it has been an ongoing discussion at ISO, many devs are fed up with such approaches, because it is the kind of stuff that prevents C++ to have nice IDE tooling like Java and .NET.
Re:Plywood: A New Cross-Platform Open Source C++ Framework by flumpcakes on Tuesday May 26, 2020 @03:25PM (#23315404)
Sorry for the noob question: can you explain how it helps with serialization or database access?

I've read simliar statements before but I don't think I understand how it helps.

Re:Plywood: A New Cross-Platform Open Source C++ Framework by jcranmer on Tuesday May 26, 2020 @03:38PM (#23315529)
The standard serialization case is basically, I have this definition:

  struct foo {
    int a;
    int b;
    const char *c;
  };
and I want to automatically generate this function:

  void serialize_foo(foo &obj, ostream &out) {
    out.serialize_int(obj.a);
    out.serialize_int(obj.b);
    out.serialize_string(obj.c);
  }
With some sort of reflection, you can automatically build that method with something like this:

  void emit_serialize_method(class_definition &clazz) {
    emit("void serialize_foo(" + clazz.name + "&obj, ostream &out) {");
    for (auto &field : clazz.fields) {
      emit("  out.serialize_" + field.type + "(obj." + field.name + ");");
    }
    emit("}");
  }
(syntax of course varies).