Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 31 15:06

    ldionne on gh-pages

    Update benchmarks to 490dbf6 fo… (compare)

  • Jan 24 07:47

    ldionne on gh-pages

    Update benchmarks to 490dbf6 fo… (compare)

  • Jan 23 02:04
    pthom commented #432
  • Jan 18 12:46

    ldionne on gh-pages

    Update benchmarks to 490dbf6 fo… (compare)

  • Jan 16 22:27
    ricejasonf commented #434
  • Jan 05 06:22
    ricejasonf commented #330
  • Jan 03 11:40

    ldionne on gh-pages

    Update benchmarks to 490dbf6 fo… (compare)

  • Jan 02 00:33
    ricejasonf closed #434
  • Jan 02 00:33
    ricejasonf commented #434
  • Jan 02 00:04
    ricejasonf opened #434
  • Dec 27 2018 13:11

    ldionne on gh-pages

    Update benchmarks to 490dbf6 fo… (compare)

  • Dec 22 2018 11:56
    pthom commented #432
  • Dec 22 2018 11:55
    pthom commented #432
  • Dec 21 2018 15:48
    pthom synchronize #432
  • Dec 21 2018 09:19
    sdebionne opened #433
  • Dec 21 2018 00:08
    ricejasonf commented #432
  • Dec 21 2018 00:03
    ricejasonf commented #432
  • Dec 20 2018 23:36
    pthom commented #432
  • Dec 20 2018 23:36
    pthom commented #432
  • Dec 20 2018 23:13
    ricejasonf commented #432
Louis Dionne
@ldionne
If, however, you can make the test cases added in #333 pass with a simpler implementation, I think I’d be happy.
Alastair Rankine
@randomphrase
Hi I have a possibly newbie question, hope someone can help.
So I want to do type manipulation on a std::tuple. Let’s just say that the std::tuple is defined elsewhere and I don’t want to change it to a hana::tuple. However I do want to do type transformations/filters on this - and I don’t mind outputting a hana::tuple.
IIUC a std::tuple can be used as a hana-conformant sequence, with the #inclusion of the appropriate adaptor. However, I can’t see a way to ‘lift’ (?) the std::tuple so that it can do type manipulations.
For instance, if I want to use std::tuple<int, char> with hana::transform (for example with hana::add_pointer), I first need to convert the std::tuple to std::tuple<hana::type_c<int>, hana::type_c<char>> - is this correct? In which case I can’t see an obvious way to do this. Does such a facility exist in Hana and if so how do I use it? Thanks.
Alastair Rankine
@randomphrase
Oops of course I need to convert std::tuple<int, char> to std::tuple<hana::type<int>, hana::type<char>>.
As it turns out I also need to convert the result (a hana::tuple<hana::type<int *>, hana::type<char *>> for example) into an MPL-conformant sequence of types such as hana::tuple<int *, char *>. Seems like a similar transformation and also seems like something that should exist in Hana already?
Maybe I’m overlooking something, FWIW I am using Hana 1.0.1 from boost 1.62.
Andreas Pokorny
@APokorny
sounds like a one liner taking a std tuple <Args...> and returing a hana::tuple<type_c<Args>...>
Alastair Rankine
@randomphrase
Sure. Something like:
template <typename ... Args>
constexpr auto to_hana_types(std::tuple<Args...>) { return hana::tuple<hana::type<Args> ...>{}; }
Seems like it should be part of hana though?
Alastair Rankine
@randomphrase
Actually I think the above ‘one-liner’ is oversimplified. In the general case (eg reference types) it may not be easy to instantiate this type, in order to call the function in the first place. Hence I think this may need to be a pure type transformation, using (for example) a partially specialized template class and traditional metaprogramming. Perhaps this is why it is not part of hana?
Jason Rice
@ricejasonf
You could do hana::transform(xs, hana::typeid_) which would yield a std::tuple<hana::type<T>...>
Jason Rice
@ricejasonf
... and types can be passed in to a hana::Metafunction like this hana::unpack(my_types, hana::template_<hana::tuple>) which would return a hana::type<hana::tuple<T...>>
There is also hana::experimental::types which is a just a list of types represented like types<T...> instead of wrapping everything in type like hana::tuple<hana::type<T>...>
Alastair Rankine
@randomphrase
@ricejasonf interesting, thanks! I’m assuming that I could also unpack into an MPL container like mpl::vector?
Alastair Rankine
@randomphrase
Also can confirm your solution works for me - including unpacking into an MPL container, nice! However, I did try it with a reference type in the input std::tuple, and sure enough I could not instantiate it to pass into hana::transform. Not sure what the generic answer would be here.
Jason Rice
@ricejasonf
Do you have a minimal code example? When dealing with types you typically want to keep it wrapped in hana::type so you don't instantiate it.
Jason Rice
@ricejasonf
boostorg/hana#326
Alastair Rankine
@randomphrase
The problem is with the first argument to hana::transform. I want to do type manipulations on a std::tuple (which as I described is generated upstream, and can’t easily be changed to a hana tuple). Currently I can call hana::transform(my_tuple{}, hana::typeid_) as you suggested above.
However this is predicated on my_tuple being default constructible, which is not necessarily the case for all tuples. Changing the default constructor to hana::type_c<my_tuple> does not work.
Jason Rice
@ricejasonf
If you just want to convert all the types to references perhaps a simple mpl style metafunction would be the most efficient.
like template <typename ...T> struct to_refs<std::tuple<T...>> { using type = std::tuple<T&...>; };
That way you don't instantiate stuff for every T
... or consider the code snippet in the top of the issue 326
Alastair Rankine
@randomphrase
Got it, sounds like #326 might be the more generic solution. Thanks for your help.
Martchus
@Martchus
To find a member by its name and the name is only known at run-time, I have to 'find it manually' by iterating over the members with hana::for_each (because hana::at_key only takes a compile-time string). Correct?
Jason Rice
@ricejasonf
Yeah, at_key requires a compile-time Comparable key.
The problem with using hana::for_each for that is that it will not short circuit. To do a run-time value to type mapping I use boost::mp11::find_with. This issue lists a few more libraries for this sort of thing. boostorg/hana#353
Martchus
@Martchus
Thanks for the response.
Martchus
@Martchus
You're talking about https://github.com/boostorg/mp11 ? I'm asking becauseboost::mp11::find_with doesn't seem to be available anymore.
Jason Rice
@ricejasonf
ah.. sorry. It's called with_index
Martchus
@Martchus
Thanks, your help is appreciated. However, I'll have to check the documentation about the usage anyways because it isn't completely obvious.
Alastair Rankine
@randomphrase
Hi, a hopefully quick question for someone. I’ve been struggling to find a solution. I have a std::tuple containing both hana::types and std::tuple<hana::type ...> I want to flatten to a single sequence of just the hana::types.
So for example:
using my_tuple = std::tuple< hana::type<A>, std::tuple< hana::type<B>, hana::type<C> > >;
auto my_types = hana::to_tuple(hana::tuple_t<A, B, C>);
How to easily transform my_tuple so that it is equal to my_types?
For the record it seems that hana::flatten will not work because it requires a sequence of sequences.
Jason Rice
@ricejasonf
An std::tuple is a hana::Sequence but you have to include it. like #include <boost/hana/ext/std/tuple.hpp>
So flatten should in fact work with that.
I think your to_tuple call is unnecessary.
Alastair Rankine
@randomphrase
Yeah I have included that header
As I said though, the reason why flatten doesn’t work is that it requires a sequence of sequences. I have a sequence which includes both sequences and non-sequences.
Jason Rice
@ricejasonf
Ah, I see so hana::type<A> is not wrapped in a tuple
I don't think there is a way around it unless you write a function to use append or concat, but really I would just make sure everything goes in as a tuple even if it only has one element.
Jason Rice
@ricejasonf
or you could use transform to normalize everything afterwards, but it feels kind of hacky:
hana::transform(my_tuple{}, [](auto x) { if constexpr(hana::is_a<hana::ext::std::tuple_tag>(x)) { return x; } else { return std::tuple{x}; } });
Alastair Rankine
@randomphrase
Yeah I think I had attempted something similar using adjust_if(my_tuple{}, [] (auto p) { return !hana::Sequence<decltype(p)>::value; }, hana::just) but it didn’t work.
In my mind I guess I had anticipated that flatten would work the way it does in lisp... maybe I’ll have to rethink this.
Jason Rice
@ricejasonf
Hana is particular about its inputs belonging to the same classification. For instance, you can't concat an std::tuple and a hana::tuple. You can't even add constants of int and unsigned int. It may seem impractical at first, but I've grown to prefer it.
adjust_if makes sense, but you are using hana::just which returns hana::optional. Could that be the problem there?
Alastair Rankine
@randomphrase
Yeah I couldn’t get adjust_if didn’t work because it ended up wrapping everything in a hana::optional, even though my predicate correctly detected sequences and returned false accordingly. So I ended up with a tuple of hana::optional<std::tuple<hana::type<A>, hana::type<B>>>, hana::optional<hana::type<C>>
Is there an online compiler with hana? Perhaps I can post a snippet if anyone is interested.
Austin McCartney
@apmccartney
Jason Rice
@ricejasonf
Yes, you gave it the function hana::justas the third argument. I would use hana::make_tuple. ;)
Alastair Rankine
@randomphrase
@ricejasonf Yeah I tried that too... Ended up with hana::tuple<std::tuple< ... >>. I’ll post a snippet to wandbox soon (thx @apmccartney)
Andreas Pokorny
@APokorny
hm is there prior art for .. compile time graph algorithms?
i.e. topology sort .. coffman graham.... or similar things
Andreas Pokorny
@APokorny
yeah I found that too, but they construct the graph at runtime.. I dont need it there..