Skip to content
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

how to handle std::array<double, 0> #158

Open
SobhanMP opened this issue Apr 26, 2024 · 2 comments
Open

how to handle std::array<double, 0> #158

SobhanMP opened this issue Apr 26, 2024 · 2 comments

Comments

@SobhanMP
Copy link

SobhanMP commented Apr 26, 2024

Hi, is the following supposed to work? What would be the "right" way of making this work? Adding an overload for std::array<T,0> doesn't work (at least template<typename T> auto serialize(const std::array<T,0> &) -> zpp::bits::members<0>; doesn't fix the problem). While the example is somewhat weird, perhaps std::vectors<std::array<double, 0>> are useful types?

https://godbolt.org/z/3vWssr3G7

#include "https://raw.githubusercontent.com/eyalz800/zpp_bits/main/zpp_bits.h"

#include <optional>
#include <vector>
#include <array>
struct S {
    std::array<double, 0> x;
    using serialize = zpp::bits::members<1>;
};

int main()
{
    auto [data, in, out] = zpp::bits::data_in_out();

    S s;

    out(s).or_throw();
}

p.s. thanks for the excellent library.

@SobhanMP SobhanMP changed the title how to handle std::array<double, 0> x; how to handle std::array<double, 0> Apr 26, 2024
@eyalz800
Copy link
Owner

I didn’t expect anyone to serialize a std::array of zero size, what is the goal you are trying to achieve by that?

@SobhanMP
Copy link
Author

SobhanMP commented Apr 26, 2024

honestly, same, but you know, it happens. I needed to have a vector of arrays to be compliant with a concept, but the concept didn't specify how big the array should be and I didn't need it so I ended up with an array of size zero (which technically take some space for some reason)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants