]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/test/data/monomorphic/zip.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / test / data / monomorphic / zip.hpp
CommitLineData
7c673cae
FG
1// (C) Copyright Gennadiy Rozental 2001.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at
4// http://www.boost.org/LICENSE_1_0.txt)
5
6// See http://www.boost.org/libs/test for the library home page.
7//
8/// @file
9/// Defines monomorphic dataset based on zipping of 2 other monomorphic datasets
10// ***************************************************************************
11
12#ifndef BOOST_TEST_DATA_MONOMORPHIC_ZIP_HPP_102211GER
13#define BOOST_TEST_DATA_MONOMORPHIC_ZIP_HPP_102211GER
14
15// Boost.Test
16#include <boost/test/data/config.hpp>
17
18#if !defined(BOOST_TEST_NO_ZIP_COMPOSITION_AVAILABLE) || defined(BOOST_TEST_DOXYGEN_DOC__)
19
20#include <boost/test/data/monomorphic/fwd.hpp>
21#include <boost/test/data/monomorphic/sample_merge.hpp>
22
92f5a8d4
TL
23#include <boost/core/enable_if.hpp>
24#include <boost/mpl/identity.hpp>
25
7c673cae
FG
26#include <boost/test/detail/suppress_warnings.hpp>
27
28
29namespace boost {
30namespace unit_test {
31namespace data {
32namespace monomorphic {
33
34// ************************************************************************** //
35// ************** zip ************** //
36// ************************************************************************** //
37
38//! Zip datasets
39//!
40//! A zip of two datasets is a dataset whose arity is the sum of the operand datasets arity. The size is given by
41//! the function creating the instance (see @c operator^ on datasets).
42template<typename DataSet1, typename DataSet2>
43class zip {
44 typedef typename boost::decay<DataSet1>::type dataset1_decay;
45 typedef typename boost::decay<DataSet2>::type dataset2_decay;
46
47 typedef typename dataset1_decay::iterator dataset1_iter;
48 typedef typename dataset2_decay::iterator dataset2_iter;
49
50public:
1e59de90 51 static const int arity = dataset1_decay::arity + dataset2_decay::arity;
7c673cae
FG
52
53 struct iterator {
54 // Constructor
55 explicit iterator( dataset1_iter iter1, dataset2_iter iter2 )
56 : m_iter1( std::move( iter1 ) )
57 , m_iter2( std::move( iter2 ) )
58 {}
59
60 using iterator_sample = decltype(
61 sample_merge( *std::declval<dataset1_iter>(),
62 *std::declval<dataset2_iter>()) );
63
64 // forward iterator interface
65 auto operator*() const -> iterator_sample {
66 return sample_merge( *m_iter1, *m_iter2 );
67 }
68 void operator++() { ++m_iter1; ++m_iter2; }
69
70 private:
71 // Data members
72 dataset1_iter m_iter1;
73 dataset2_iter m_iter2;
74 };
75
7c673cae
FG
76 //! Constructor
77 //!
78 //! The datasets are moved and not copied.
92f5a8d4 79 zip( DataSet1&& ds1, DataSet2&& ds2/*, data::size_t size*/ )
7c673cae
FG
80 : m_ds1( std::forward<DataSet1>( ds1 ) )
81 , m_ds2( std::forward<DataSet2>( ds2 ) )
92f5a8d4 82 //, m_size( size )
7c673cae
FG
83 {}
84
85 //! Move constructor
86 zip( zip&& j )
87 : m_ds1( std::forward<DataSet1>( j.m_ds1 ) )
88 , m_ds2( std::forward<DataSet2>( j.m_ds2 ) )
92f5a8d4 89 //, m_size( j.m_size )
7c673cae
FG
90 {}
91
92 // dataset interface
92f5a8d4 93 data::size_t size() const { return zip_size(); }
7c673cae
FG
94 iterator begin() const { return iterator( m_ds1.begin(), m_ds2.begin() ); }
95
96private:
97 // Data members
98 DataSet1 m_ds1;
99 DataSet2 m_ds2;
92f5a8d4
TL
100 //data::size_t m_size;
101
102
103 //! Handles the sise of the resulting zipped dataset.
104 data::size_t zip_size() const
105 {
106 data::size_t ds1_size = m_ds1.size();
107 data::size_t ds2_size = m_ds2.size();
108
109 if( ds1_size == ds2_size )
110 return ds1_size;
111
112 if( ds1_size == 1 || ds1_size.is_inf() )
113 return ds2_size;
114
115 if( ds2_size == 1 || ds2_size.is_inf() )
116 return ds1_size;
117
118 BOOST_TEST_DS_ERROR( "Can't zip datasets of different sizes" );
119 }
7c673cae
FG
120};
121
122//____________________________________________________________________________//
123
124//! Zipped datasets results in a dataset.
125template<typename DataSet1, typename DataSet2>
126struct is_dataset<zip<DataSet1,DataSet2>> : mpl::true_ {};
127
128//____________________________________________________________________________//
129
7c673cae
FG
130namespace result_of {
131
132//! Result type of the zip operator.
133template<typename DS1Gen, typename DS2Gen>
134struct zip {
135 typedef monomorphic::zip<typename DS1Gen::type,typename DS2Gen::type> type;
136};
137
138} // namespace result_of
139
140//____________________________________________________________________________//
141
142//! Overload operator for zip support
143template<typename DataSet1, typename DataSet2>
144inline typename boost::lazy_enable_if_c<is_dataset<DataSet1>::value && is_dataset<DataSet2>::value,
145 result_of::zip<mpl::identity<DataSet1>,mpl::identity<DataSet2>>
146>::type
147operator^( DataSet1&& ds1, DataSet2&& ds2 )
148{
149 return zip<DataSet1,DataSet2>( std::forward<DataSet1>( ds1 ),
92f5a8d4
TL
150 std::forward<DataSet2>( ds2 )/*,
151 ds_detail::zip_size( ds1, ds2 )*/ );
7c673cae
FG
152}
153
154//____________________________________________________________________________//
155
156//! @overload boost::unit_test::data::monomorphic::operator^()
157template<typename DataSet1, typename DataSet2>
158inline typename boost::lazy_enable_if_c<is_dataset<DataSet1>::value && !is_dataset<DataSet2>::value,
159 result_of::zip<mpl::identity<DataSet1>,data::result_of::make<DataSet2>>
160>::type
161operator^( DataSet1&& ds1, DataSet2&& ds2 )
162{
163 return std::forward<DataSet1>( ds1 ) ^ data::make( std::forward<DataSet2>( ds2 ) );
164}
165
166//____________________________________________________________________________//
167
168//! @overload boost::unit_test::data::monomorphic::operator^()
169template<typename DataSet1, typename DataSet2>
170inline typename boost::lazy_enable_if_c<!is_dataset<DataSet1>::value && is_dataset<DataSet2>::value,
171 result_of::zip<data::result_of::make<DataSet1>,mpl::identity<DataSet2>>
172>::type
173operator^( DataSet1&& ds1, DataSet2&& ds2 )
174{
175 return data::make( std::forward<DataSet1>( ds1 ) ) ^ std::forward<DataSet2>( ds2 );
176}
177
178} // namespace monomorphic
179} // namespace data
180} // namespace unit_test
181} // namespace boost
182
183#include <boost/test/detail/enable_warnings.hpp>
184
185#endif // BOOST_TEST_NO_ZIP_COMPOSITION_AVAILABLE
186
187#endif // BOOST_TEST_DATA_MONOMORPHIC_ZIP_HPP_102211GER
188