boost-ext / te

C++17 Run-time Polymorphism (Type Erasure) library
451 stars 38 forks source link

Question: maturity #29

Closed pfeatherstone closed 2 years ago

pfeatherstone commented 3 years ago

NOT A BUG

How mature is this library? Is this production ready? Are there any big differences to the dyno library? I noticed dyno seems to be a bit bigger so was wondering if that's because it handles corner cases, or subtle cases that need special handling. The only differences to dyno I can see are different storage policies for vtable and the fact you can partially inline functions in the vtable and partially put the rest on the heap. So there is more configurability I guess. But if you don't care about that, would you say this library gives you equal functionality to dyno?

Finally, is it possible to port this library to C++14 or would that require substantial more code or the use of big libraries like boost::mpl or something like that?

pfeatherstone commented 2 years ago

Just tried it, with a bit of fiddling, you can make this C++14 compatible. I've tried it with gcc5.5 and it works. You have to remove a few constexprs and replace a fold expression with a parameter pack expansion into a dummy array or initializer list.

Basically you have to replace:

(init<Ns + 1, std::decay_t<T> >(
         decltype(get(detail::mappings<I, Ns + 1>{})){}),
     ...);

with

(void)std::initializer_list<int>{
        (init<Ns + 1, std::decay_t<T>>(decltype(get(detail::mappings<I, Ns + 1>{})){}), 0)...
    };

That's it. I tried making it C++11 compatible but that's a bit harder. You have to remove all the constexpr and I don't know how you make the following work. But I'm sure there is a way.

template <class, std::size_t>
struct mappings final {
  friend auto get(mappings);
  template <class T>
  struct set {
    friend auto get(mappings) { return T{}; }
  };
};
pfeatherstone commented 2 years ago

A tutorial or talk on how this stuff works would be great. Bits of this look like complete sorcery