-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot use decode with std::array #32
Comments
Hi, cppcodec/data/access.hpp contains the basic level of of access, which is not push_back() (that's just the default) but a set of template functions to implement for the given type. Quoting https://github.com/tplgy/cppcodec/blob/master/cppcodec/data/access.hpp#L32
(Also just noticed that I wrote "State" instead of "ResultState" in one place. Please excuse this mistake.) I'd have to look into the trade-offs of using iterator ranges for constructors. Off the top of my head, iterators don't have .size() functions so unless the size is encoded in the type itself, like for Do you want to try implementing the above-mentioned functions for |
They don't indeed, but one can use I just remembered If I understood correctly, one has to specialize several methods for its custom type, including However, this is inconvenient for fixed-size containers like I could take a look this week-end yes. |
The last position inserted is something that's always going to be necessary - iterators would keep one such variable around, in my case here I'm using a ResultState& to keep the position around in between calls. For Actually this brings up an interesting point - how were you going to call |
Also note that you're always able to use the |
Finally, I was going to correct my above statement about |
I believe it was something like this: auto decoded = base64::decode<std::array<uint8_t, 32>>(encodedText);
From that statement, I assume you are storing characters one by one? That would explain the Maybe we could try to replace that mechanism (or at least overhaul it) with the support of iterator ranges, e.g. by adding methods in I will take a further look to the code to better understand the design choices, to avoid asking questions here and make you lose time. |
Thanks, I appreciate your thoughtful replies. The challenge with using the API like this is that you have to know the size of
That said, since cppcodec takes responsibility for both initializing and populating the array, and you don't need it to be constructed as const, I feel like there might be an easier (iterator-less) solution to the issue. I look forward to your findings :) |
Hello, did you have time to look at the PR? |
I fixed the PR, but I did introduce a copy for simplicity. Let me know if you have a better solution, I'll try to allocate a bit of time to dig deeper in the library's code. |
Hello,
It seems you are forcing the
Result
template type to have apush_back
method, whichstd::array
doesn't have.I was wondering if it would be easy to use the iterator range constructors of standard containers instead, to allow using a lot more container types.
I didn't dive into the code yet, do you think this is an easy change? If so, I could open a PR soon.
Thanks
The text was updated successfully, but these errors were encountered: