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
Adi Shavit
@adishavit
Hi folks, @ldionne

A question about Hana:
Say I want to incrementally collect data in a tuple (or an equivalent heterogeneous container), i.e. incrementally add another value (and type) to the tuple.

I could use std::tuple_cat but I would need to copy and store the result in a different local variable for each such cat.

I can’t use std::any since I won’t know the contained type. Is there such a way to extract the contained type of an any?

Is it possible to have a single local variable that supports such "insert"s preferably without copying?

Does Hana have such a facility?

One obvious way to do this is to incrementally serialize the data (e.g. to json) and reparse it later, but this seems a bit roundabout.

Adi Shavit
@adishavit
I’ve made some more clarifications in the SO question.
Jason Rice
@ricejasonf
@adishavit If you have to make the tuple incrementally there is no getting away from the copy/move of each element each time you append. You could definitely get rid of the "clutter" of moved from objects by breaking each of those //... operations into separate functions. IMO large multipurpose functions are a bit of a no-no anyways. :coffee:
The only reason you would need to make a tuple incrementally is if each of those operations depended on the results of the previous operations.
Adi Shavit
@adishavit
It actually might.
The reason I wanted this is to collect data for later serialization e.g. to csv or json.
I wanted to serialize or the end and not throughout the process.
Leon washbrook
@LeonWashbrook_twitter
James Brock
@jamesdbrock
wow I just saw Hana for the first time, it's awesome, congratulations @ldionne .
Scott Santucci
@ScottFreeCode
Does the BOOST_HANA_DEFINE_STRUCT macro support giving the struct members default values? Or would I have to use regular structs and the BOOST_HANA_ADAPT_STRUCT macro?
Jason Rice
@ricejasonf
I doubt the macro supports it. not at my comp to check tho
Scott Santucci
@ScottFreeCode
Also, I'm sort of trying to reverse the serialization example -- read in data (at runtime) and use it to set the value of the field that matches the key if there is a matching key in the struct; is this sort of thing possible? I'm a little stuck on checking for or comparing against a runtime string instead of a hana::string; I eventually tried a comparison using find_if and a predicate that uses .c_str(), but that didn't work (gave an error that doesn't really say anything meaningful to me and I'm not sure which part of the infodump is relevant). Any pointers (pun not intended)?
[edits for clarity]
Jason Rice
@ricejasonf
I did this in my project nbdl with jsoncpp. dont remember how i dis the equals check
*did
Scott Santucci
@ScottFreeCode
Jason Rice
@ricejasonf
yes it doesnt use hana::Struct but its the same concept
Scott Santucci
@ScottFreeCode
Aaah.
Interesting; I will see if I can find what it's doing. Thanks.
Scott Santucci
@ScottFreeCode
I think I might be able to do it with an ordinary runtime loop instead of a Hana algorithm (I suspect the root of my problem is that the Hana functions all act at compile-time) provided I can find a way to get the length of the accessors list... or have a way to convert the accessors list into a runtime list that would have a length available.
Aha -- hana::length(Foldable) ought to do it? Let me fiddle with the code and see.
Hmm, that won't quite work -- I can only get the accessor at a given index if the index is a compile-time variable.
Jason Rice
@ricejasonf
I'm not sure what you mean. Do you have a code snippet to show?
Hana functions do not necessarily run at compile-time, but the length of a hana::Foldable is known at compile-time. You shouldn't need to put it in a run-time list.
Scott Santucci
@ScottFreeCode
Let me see if any of my half-baked attempts is still in the undo history over here...
Scott Santucci
@ScottFreeCode
So, I expect this to fail on line 36, but it fails on line 29. http://melpon.org/wandbox/permlink/NGxu6Xcs3LjwiBut
Scott Santucci
@ScottFreeCode
(Of course, I really can't tell what the error message means. So it's entirely conceivable that I'm just doing something wrong C++-wise?)
(Now, the fact that I can't use the optional result this way, I'm well aware of; I just didn't want to hold up the example figuring out how to adequately code "continue parsing only if the field is valid, otherwise stop with an error". So I put in a bad, un-functional placeholder.)
(But that's a moot point unless I can search for the field by runtime data in the first place.)
Jason Rice
@ricejasonf
I'm pretty sure the predicate to find_if must return a compile-time bool. The std::stringvalue is only known at run-time.
Scott Santucci
@ScottFreeCode
Right, that's why I was trying to think of a way to search the list at runtime...
Jason Rice
@ricejasonf
Ah yeah, using jsoncpp I guess I didn't have to deal with that. Mapping run-time stuff to compile-time stuff can be tricky. I made a variant type that maps a sequential index to each of its types. You could possibly do the same thing except use a hash of the field name to map to each field. Since each field would potentially be of different types, you couldn't simply return it from a lookup function. I believe the only way to get around this is to provide a function that takes the result as a parameter.
Scott Santucci
@ScottFreeCode
Since my use case is just reversing Hana's excellent serialization abilities, I don't think I need to worry too much about different types as long as I can come up with something that will convert the value string to whichever field's type it finds (probably like visiting a variant, yeah, except that the list is more like a std::tuple with a std::map-like search ability and no dynamic allocation since the keys and the values' types are both known at compile-time)... And converting Hana's struct accessor lists to such a type should be entirely doable as well, using Hana's compile-time computation abilities. So I just have to work through implementing that type. Yeah, this is gonna be more work than I originally assumed but it should be entirely doable.
I will take a look at jsoncpp and see how much I can learn from your case; thanks!
And thanks for helping me work through the ideas involved.
(If anybody knows of an already-existing compile-time-generated runtime-searchable homogenous-keyed heterogenous-valued object, let me know, because I'd love to be able to just borrow another existing library. Although optimizing it for the case of searching on C strings would be pretty cool too [e.g. start by sorting into buckets by string length so the rest of the search has a significantly smaller space, as finding the bucket with matching length should be quick in and of itself]...)
Scott Santucci
@ScottFreeCode
Still would be better with a runtime-usable, compile-time-populated, dynamic-allocation-free hash map (or similarly used keyed data structure), but it's going to take me longer to learn how to build that, heh.
(There's also probably some simplifications or general improvements I can make; will keep learning and refining.)
By the way, ldionne, in case I haven't said it already, Hana is one of the most amazing things I've ever seen in C++. Great work! :clap:
Jason Rice
@ricejasonf
Cool. I didn't check to see if it made a difference, but both build_array and uniform_accessors can be marked constexpr.
Scott Santucci
@ScottFreeCode
Good point; thanks. And I could probably get rid of or shorten some of those lengthy/repetitious type specifications somehow too...
Scott Santucci
@ScottFreeCode
Are there any good techniques for working with Hana and enums? (I might just ask myself to reevaluate what I'm using an enum for and see if I can't create a class that does it at least as well and interoperates with Hana directly, but I figured I'd ask before reinventing the wheel.)
Jason Rice
@ricejasonf
I don't think Hana has anything for working with enum. I personally don't use them at all.
Scott Santucci
@ScottFreeCode
The more I think about it, the more I suspect I don't need to get Hana to do anything with them because what I'd be doing would be better done in Hana without them. At least, for the use case I have in mind at the moment.
I mean, I basically want a fixed/closed set of named, unique values. I should be able to come up with a way to get that in Hana's natural paradigm of compile-time type programming with values holding types, rather than trying to come up with a way to hack introspection onto enums or something like that. Or at least, my intuition is wiggling its eyebrows and gesturing in that general direction.
Scott Santucci
@ScottFreeCode
...Oh. I should really think through what I need at compile-time and what I need at runtime and see if traditional C++ programming would suffice anyway.
Jason Rice
@ricejasonf
boostorg/hana#324
^ I realized that bucket_insert is used inside insert