How to convert tuple to byte array in c++11

前端 未结 2 1443
梦毁少年i
梦毁少年i 2021-01-14 16:02

I need to write a function to convert tuple to byte array. The type of tuple may include int, long, double, std::string, char*,etc. The size and type of tuple a

2条回答
  •  臣服心动
    2021-01-14 16:44

    There is also the brilliant C++ API for message pack which supports tuples natively

    #include 
    #include 
    #include 
    
    #include 
    
    int main() {
        auto t = std::make_tuple("1", 1, 1.0);
        auto buffer = std::stringstream{};
    
        // easy peezy
        msgpack::pack(buffer, t);
        auto tuple_as_string = buffer.str();
    }
    

提交回复
热议问题