1

I'm searching some kind of meta vector/linked list. Seems like mpl::vector was the best way of doing this. But now there is hana. Unfortunately I can't find some kind of hana::vector. I saw an adapter for mpl::vector that's all. So that's mean mpl::vector is still the best way of doing things?

Hana was pretty quick to compile so I was like : well why not? But mpl is not that fast, do I really need to code mpl::vector myself?

Mathieu Van Nevel
  • 1,428
  • 1
  • 10
  • 26
  • 1
    Why doesn't [`hana::tuple`](http://www.boost.org/doc/libs/1_62_0/libs/hana/doc/html/structboost_1_1hana_1_1tuple.html) work for you? – Vittorio Romeo Jan 05 '17 at 14:45
  • `mpl::*` stuff is quite old, it is pre-C++11. For example, a lot of things than nowadays are done through simple paramter pack expansion are still done through recursive templates in `mpl`. It is going to be considerably slower than modern code. And yes, coding `vector` in C++14 is a piece of cake and can easily be done if `mpl::vector` is not satsficatory. – SergeyA Jan 05 '17 at 15:14

1 Answers1

3

boost::hana::tuple should be a good-enough replacement for mpl::vector if what you need is a heterogeneous "list" of types/values.

You can access an item in a particular index with boost::hana::at, append items with boost::hana::append, remove them with boost::hana::remove and much more.

Even if there isn't a 1-to-1 correspondence to mpl::vector's interface, it should be trivial to implement some utility functions given the primitives mentioned above.


If you need a list of types, you should use boost::hana::tuple_t, which is syntactic sugar for hana::tuple(hana::type_c<Types>...).

Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416
  • `mpl::vector` is a list of types, not values. It is different from `hana::tuple`. – SergeyA Jan 05 '17 at 15:12
  • 1
    In `boost::hana` types are values - that's a core principle of the library. E.g. `hana::make_tuple(hana::type_c, hana::type_c)` – Vittorio Romeo Jan 05 '17 at 15:29
  • Seems like there is no other choice :) now I'll just check if std::tuple is not enough with C++17. Thanks – Mathieu Van Nevel Jan 06 '17 at 09:54
  • FWIW, `hana::tuple` will compile _much_ faster than `std::tuple`, because a standard-conforming implementation of tuple needs to have a lot of crazy constructors. Unless you really need the full flexibility of `std::tuple` (like allocator constructor), you might want to stick with `hana::tuple`. – Louis Dionne Jan 07 '17 at 21:48
  • Well I just need to have less dependencies possible, so I'm going to check if std::tuple is enough (speed include), and choose after. – Mathieu Van Nevel Jan 09 '17 at 13:11