Skip to content

Problem serializing std::tuple #22

Description

@mspertus

I am not able to get tuples to serialize using g++ 11.3.0 on ubuntu 22.04.

Here's my program

#include <alpaca/alpaca.h>
#include <tuple>
std::tuple<int, double> t(1, 2.3);

std::vector<uint8_t> bytes;
auto bytes_written = alpaca::serialize(t, bytes); 

which fails to compile as follows

g++ -std=c++17 -I../build/_deps/alpaca-src/include/ test_alpaca.cpp 
In file included from ../build/_deps/alpaca-src/include/alpaca/alpaca.h:9,
                 from test_alpaca.cpp:1:
../build/_deps/alpaca-src/include/alpaca/detail/struct_nth_field.h: In instantiation of ‘constexpr decltype(auto) alpaca::detail::get(type&) [with long unsigned int index = 0; type = const std::tuple<int, double>&; long unsigned int arity = 4]’:
../build/_deps/alpaca-src/include/alpaca/alpaca.h:139:60:   required from ‘void alpaca::detail::serialize_helper(const T&, Container&, std::size_t&) [with alpaca::options O = alpaca::options::none; T = std::tuple<int, double>; long unsigned int N = 4; Container = std::vector<unsigned char>; long unsigned int I = 0; std::size_t = long unsigned int]’
../build/_deps/alpaca-src/include/alpaca/alpaca.h:156:62:   required from ‘std::size_t alpaca::serialize(const T&, Container&) [with T = std::tuple<int, double>; long unsigned int N = 4; Container = std::vector<unsigned char>; std::size_t = long unsigned int]’
test_alpaca.cpp:8:39:   required from here
../build/_deps/alpaca-src/include/alpaca/detail/struct_nth_field.h:41:11: error: 4 names provided for structured binding
   41 |     auto &[p1, p2, p3, p4] = value;
      |           ^~~~~~~~~~~~~~~~
../build/_deps/alpaca-src/include/alpaca/detail/struct_nth_field.h:41:11: note: while ‘const std::tuple<int, double>’ decomposes into 2 elements

Any thoughts appreciated.
Thanks,
Mike

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions