ttg 1.0.0
Template Task Graph (TTG): flowgraph-based programming model for high-performance distributed-memory algorithms
Loading...
Searching...
No Matches
boost.h
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2//
3// Created by Eduard Valeyev on 5/3/21.
4//
5
6#ifndef TTG_SERIALIZATION_BOOST_H
7#define TTG_SERIALIZATION_BOOST_H
8
9#include <type_traits>
10
11#if __has_include(<boost/type_traits/is_array.hpp>)
12# define TTG_HAS_BOOST_HEADERS 1
13# include <boost/type_traits/is_array.hpp>
14# include <boost/type_traits/remove_extent.hpp>
15#endif
16
17#ifdef TTG_SERIALIZATION_SUPPORTS_BOOST
18#include <boost/archive/binary_iarchive.hpp>
19#include <boost/archive/binary_oarchive.hpp>
20#include <boost/serialization/level.hpp>
21#endif // TTG_SERIALIZATION_SUPPORTS_BOOST
22
23namespace ttg::detail {
24
25 /*----- is_boost_{input,output,}_archive_v -----*/
26
27#ifdef TTG_SERIALIZATION_SUPPORTS_BOOST
28 template <typename T>
29 inline constexpr bool is_boost_archive_v = std::is_base_of_v<boost::archive::detail::basic_iarchive, T> ||
30 std::is_base_of_v<boost::archive::detail::basic_oarchive, T>;
31 template <typename T>
32 inline constexpr bool is_boost_input_archive_v = std::is_base_of_v<boost::archive::detail::basic_iarchive, T>;
33
34 template <typename T>
35 inline constexpr bool is_boost_output_archive_v = std::is_base_of_v<boost::archive::detail::basic_oarchive, T>;
36
37 /*----- is_archive_v for boost archives -----*/
38 template <typename T>
39 inline constexpr bool is_archive_v<T, std::enable_if_t<is_boost_archive_v<T>>> = true;
40 template <typename T>
41 inline constexpr bool is_input_archive_v<T, std::enable_if_t<is_boost_input_archive_v<T>>> = true;
42 template <typename T>
43 inline constexpr bool is_output_archive_v<T, std::enable_if_t<is_boost_output_archive_v<T>>> = true;
44
45#else // TTG_SERIALIZATION_SUPPORTS_BOOST
46 template <typename T>
47 inline constexpr bool is_boost_archive_v = false;
48 template <typename T>
49 inline constexpr bool is_boost_input_archive_v = false;
50 template <typename T>
51 inline constexpr bool is_boost_output_archive_v = false;
52#endif // TTG_SERIALIZATION_SUPPORTS_BOOST
53
54 /*----- is_boost_serializable_v -----*/
55
56 template <typename Archive, typename T, typename Enabler = void>
57 inline static constexpr bool is_boost_serializable_v = false;
58
59 template <typename Archive, typename T, typename Enabler = void>
61
62#ifdef TTG_HAS_BOOST_HEADERS
63 template <typename Archive, typename T>
64 struct is_boost_array_serializable<Archive, T, std::enable_if_t<!boost::is_array<T>::value>> : std::false_type {};
65
66 template <typename Archive, typename T>
67 struct is_boost_array_serializable<Archive, T, std::enable_if_t<boost::is_array<T>::value>>
68 : std::bool_constant<is_boost_serializable_v<Archive, boost::remove_extent_t<T>>> {};
69#else
70 template <typename Archive, typename T>
71 struct is_boost_array_serializable<Archive, T> : std::false_type {};
72#endif
73
74 template <typename Archive, typename T>
75 inline static constexpr bool is_boost_array_serializable_v = is_boost_array_serializable<Archive, T>::value;
76
77 template <typename Archive, typename T>
78 inline static constexpr bool is_stlcontainer_boost_serializable_v = false;
79
80#ifdef TTG_SERIALIZATION_SUPPORTS_BOOST
85 template <typename Archive, typename T>
86 inline static constexpr bool is_boost_serializable_v<
87 Archive, T,
88 std::enable_if_t<
89 // Archive is a boost archive
90 is_boost_archive_v<Archive>
91 // T is not not_serializable
92 && !std::is_same_v<typename boost::serialization::implementation_level<T>::type,
93 boost::mpl::int_<boost::serialization::level_type::not_serializable>>
94 // T is primitive or T is an array of serializables or else T has serialize methods
95 && (std::is_same_v<typename boost::serialization::implementation_level<T>::type,
96 boost::mpl::int_<boost::serialization::level_type::primitive_type>> ||
97 is_boost_array_serializable_v<Archive, T> ||
98 (!std::is_same_v<typename boost::serialization::implementation_level<T>::type,
99 boost::mpl::int_<boost::serialization::level_type::primitive_type>> &&
100 (ttg::detail::has_freestanding_serialize_with_version_v<ttg::meta::remove_cvr_t<T>, Archive> ||
101 (ttg::detail::is_stlcontainer_boost_serializable_v<Archive, T> &&
102 ttg::detail::has_freestanding_boost_serialize_with_version_v<ttg::meta::remove_cvr_t<T>, Archive>) ||
104 (ttg::detail::has_member_load_with_version_v<T, Archive> &&
105 ttg::detail::has_member_save_with_version_v<T, Archive>))))>> = true;
106#endif // TTG_SERIALIZATION_SUPPORTS_BOOST
107
108 template <typename Archive, typename T>
109 struct is_boost_serializable : std::bool_constant<is_boost_serializable_v<Archive, T>> {};
110
111 template <typename Archive, typename T, class = void>
112 struct is_boost_default_serializable : std::false_type {};
113
114#ifdef TTG_SERIALIZATION_SUPPORTS_BOOST
116 template <typename Archive, typename T>
118 Archive, T,
119 std::enable_if_t<
120 // Archive is a boost archive
121 is_boost_archive_v<Archive>
122 // T is not not_serializable
123 && !std::is_same_v<typename boost::serialization::implementation_level<T>::type,
124 boost::mpl::int_<boost::serialization::level_type::not_serializable>>
125 // T is primitive or T is an array of serializables or else T has serialize methods
126 && (std::is_same_v<typename boost::serialization::implementation_level<T>::type,
127 boost::mpl::int_<boost::serialization::level_type::primitive_type>> ||
128 is_boost_array_serializable_v<Archive, T> ||
129 (!std::is_same_v<typename boost::serialization::implementation_level<T>::type,
130 boost::mpl::int_<boost::serialization::level_type::primitive_type>> &&
131 (ttg::detail::is_stlcontainer_boost_serializable_v<Archive, T> &&
132 ttg::detail::has_freestanding_boost_serialize_with_version_v<ttg::meta::remove_cvr_t<T>, Archive>)))>>
133 : std::true_type {};
134#endif // TTG_SERIALIZATION_SUPPORTS_BOOST
135
136 template <typename Archive, typename T>
137 inline static constexpr bool is_boost_default_serializable_v = is_boost_default_serializable<Archive, T>::value;
138
139 template <typename T, class = void>
140 struct is_boost_buffer_serializable : std::false_type {};
141
142#ifdef TTG_SERIALIZATION_SUPPORTS_BOOST
143 template <typename T>
144 struct is_boost_buffer_serializable<T, std::enable_if_t<is_boost_serializable_v<boost::archive::binary_iarchive, T> &&
145 is_boost_serializable_v<boost::archive::binary_oarchive, T>>>
146 : std::true_type {};
147#endif // TTG_SERIALIZATION_SUPPORTS_BOOST
148
150 template <typename T>
152
153 template <typename T, class = void>
154 struct is_boost_default_buffer_serializable : std::false_type {};
155
156#ifdef TTG_SERIALIZATION_SUPPORTS_BOOST
157 template <typename T>
159 T, std::enable_if_t<is_boost_default_serializable_v<boost::archive::binary_iarchive, T> &&
160 is_boost_default_serializable_v<boost::archive::binary_oarchive, T>>> : std::true_type {};
161#endif // TTG_SERIALIZATION_SUPPORTS_BOOST
162
164 template <typename T>
166
168 template <typename T>
170 is_boost_buffer_serializable<T>::value && !is_boost_default_buffer_serializable_v<T>;
171
172} // namespace ttg::detail
173
174#endif // TTG_SERIALIZATION_BOOST_H
STL namespace.
constexpr bool is_boost_output_archive_v
Definition boost.h:51
constexpr bool has_member_serialize_with_version_v
Definition traits.h:92
constexpr bool is_boost_archive_v
Definition boost.h:47
constexpr bool is_boost_default_buffer_serializable_v
evaluates to true if can serialize T to/from buffer using default Boost serialization
Definition boost.h:165
constexpr bool is_boost_user_buffer_serializable_v
evaluates to true if can serialize T to/from buffer using user-provided Boost serialization
Definition boost.h:169
constexpr bool is_boost_input_archive_v
Definition boost.h:49
constexpr bool is_boost_buffer_serializable_v
evaluates to true if can serialize T to/from buffer using Boost serialization
Definition boost.h:151
std::remove_cv_t< std::remove_reference_t< T > > remove_cvr_t
Definition meta.h:25