These are chat archives for boostorg/hana

8th
Jul 2017
Shreyans
@shreyans800755
Jul 08 2017 16:14

@badair You can print the type of complex templated data type using the following:

template<typename T>
void print_T() { std::cout << __PRETTY_FUNCTION__ << '\n'; }
print_T(decltype(grouped));

FYI

Instead of getting it as error message
Jason Rice
@ricejasonf
Jul 08 2017 17:24
I had no idea you could do that. Your print_T has to take a T as an argument though.
The problem with that is that you have to include iostream, compile and run the program to see what T is. still a neat trick
Barrett Adair
@badair
Jul 08 2017 20:32

So, what is the best way to transform this:

hana::tuple<
    hana::pair<A, B>,
    hana::pair<A, C>,
    hana::pair<B, C>,
    hana::pair<A, D>,
    hana::pair<B, D>>

into something like this:

hana::tuple< /*map*/
    hana::pair<A, hana::tuple<B, C, D>>,
    hana::pair<B, hana::tuple<C, D>>>
I'm playing around with monadic_fold_left
Jason Rice
@ricejasonf
Jul 08 2017 20:37
Is using monadic_fold_left a requirement?
Barrett Adair
@badair
Jul 08 2017 20:37
nope
I have a compile-time list of pairs that I want to transform/flatten into a map of first -> tuple<second...> if that makes sense
I'm exploring some ideas for a compile-time graph
Jason Rice
@ricejasonf
Jul 08 2017 20:42
I think sort then group would be good unless there are only two keys then partition would be better
Barrett Adair
@badair
Jul 08 2017 20:42
okay thanks
what if the types don't have an ordering though
Jason Rice
@ricejasonf
Jul 08 2017 20:43
oh yeah :sweat_smile:
You could even use fold_left but it will be very slow
I'll take a hack at it later
Barrett Adair
@badair
Jul 08 2017 20:59
I did it with fold_left like this
but it's probably a slow way to do it
Louis Dionne
@ldionne
Jul 08 2017 22:19
@badair @ricejasonf For info, I’m trying to fix C++1z issues: boostorg/hana#361
Jason Rice
@ricejasonf
Jul 08 2017 22:35
Sweet!
Barrett Adair
@badair
Jul 08 2017 23:42
Is there a customization point for Hashable in the same way that you can define equal to satisfy Comparable?
Jason Rice
@ricejasonf
Jul 08 2017 23:42
hana::hash_impl
Do you really need that?
Barrett Adair
@badair
Jul 08 2017 23:42
is that part of the stable interface?
Jason Rice
@ricejasonf
Jul 08 2017 23:42
yes
Barrett Adair
@badair
Jul 08 2017 23:42
Yes I do
Barrett Adair
@badair
Jul 08 2017 23:44
I don't see hash_impl in the documentation -- how do you customize it for your own type?
Jason Rice
@ricejasonf
Jul 08 2017 23:44
watch my video :P
you specialize hash_impl for your datatype's tag
the public facing function is just hana::hash
Barrett Adair
@badair
Jul 08 2017 23:46
I already did! Don't remember that part. Okay thanks
Jason Rice
@ricejasonf
Jul 08 2017 23:46
I'm really curious about the use case you have for it
Barrett Adair
@badair
Jul 08 2017 23:47
Let me back up then. Is there a type in Hana that's like hana::type but lets you store a value of that type inside? I didn't find one so I made one myself.
Jason Rice
@ricejasonf
Jul 08 2017 23:49
Wouldn't that be just an instance of the value of that type?
Barrett Adair
@badair
Jul 08 2017 23:49
Yeah. Does hana::type<T> have a member of type T?
bc that's what I need
Jason Rice
@ricejasonf
Jul 08 2017 23:50
using Foo = typename my_type::type;
Do your As and Bs have run-time state?
Barrett Adair
@badair
Jul 08 2017 23:51
yes
which is what makes Hana so perfect for my use case
Barrett Adair
@badair
Jul 08 2017 23:57
this is what I ended up doing:
// todo this shouldn't be necessary
template<typename T>
struct type_v {
    T value;

    template<typename U>
    constexpr auto equal(U) const {
        return std::is_same<T, U>{};   
    }
};
Jason Rice
@ricejasonf
Jul 08 2017 23:59
If it was me I would do hana::pair<hana::type<T>, hana::pair<T, V>>