Bond
 
Loading...
Searching...
No Matches
tuple.h
1// Copyright (c) Microsoft. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
4#pragma once
5
6#include <bond/core/config.h>
7
8#include "bond.h"
9#include "detail/tuple_fields.h"
10
11#include <tuple>
12
13namespace bond
14{
15
16// Specialize bond::schema<T> for std::tuple<T...>
17// This allows treating instances of std::tuple as Bond structs.
18template <typename ...T>
19struct schema<std::tuple<T...>>
20{
21 struct type
22 {
23 typedef no_base base;
24 typedef typename detail::tuple_fields<std::tuple<T...>, 0, T...>::type fields;
25
26 static const Metadata metadata;
27
28 type()
29 {
30 // Force instantiation of template statics
31 (void)metadata;
32 }
33
34 static Metadata GetMetadata()
35 {
36 Metadata m = reflection::MetadataInit(
37 "tuple", "bond.tuple", reflection::Attributes());
38
39 std::string params;
40
41 boost::mpl::for_each<typename detail::param_list<T...>::type>(
42 detail::TypeListBuilder(params));
43
44 m.name += "<" + params + ">";
45 m.qualified_name += "<" + params + ">";
46
47 return m;
48 }
49 };
50};
51
52
53template <typename... T>
54const Metadata schema<std::tuple<T...>>::type::metadata
55 = schema<std::tuple<T...>>::type::GetMetadata();
56
57
58template <typename Protocols = BuiltInProtocols, typename Writer, typename... T>
59inline void Pack(Writer& writer, T&&... args)
60{
61 Serialize<Protocols>(std::forward_as_tuple(args...), writer);
62}
63
64
65template <typename Protocols = BuiltInProtocols, typename Reader, typename... T>
66inline void Unpack(Reader reader, T&... arg)
67{
68 auto pack = std::tie(arg...);
69 Deserialize<Protocols>(reader, pack);
70}
71
72} // namepsace bond
namespace bond
Definition: apply.h:17
STL namespace.