@@ -16,6 +16,7 @@ Distributed under the Boost Software License, Version 1.0.
16
16
#include < boost/hana/and.hpp>
17
17
#include < boost/hana/at.hpp>
18
18
#include < boost/hana/bool.hpp>
19
+ #include < boost/hana/cartesian_product.hpp>
19
20
#include < boost/hana/config.hpp>
20
21
#include < boost/hana/detail/algorithm.hpp>
21
22
#include < boost/hana/detail/decay.hpp>
@@ -58,6 +59,43 @@ BOOST_HANA_NAMESPACE_BEGIN
58
59
detail::is_view<Sequence>::value, Sequence, Sequence&
59
60
>::type;
60
61
62
+ // ////////////////////////////////////////////////////////////////////
63
+ // cartesian_product_element_view
64
+ // ////////////////////////////////////////////////////////////////////
65
+ template <typename Sequences, std::size_t i>
66
+ struct cartesian_product_element_view_t {
67
+ detail::view_storage<Sequences> sequences_;
68
+ using hana_tag = view_tag;
69
+ };
70
+
71
+ template <typename Sequences, std::size_t i>
72
+ struct is_view <cartesian_product_element_view_t <Sequences, i>> {
73
+ static constexpr bool value = true ;
74
+ };
75
+
76
+ // ////////////////////////////////////////////////////////////////////
77
+ // cartesian_product_view
78
+ // ////////////////////////////////////////////////////////////////////
79
+ template <typename Sequences>
80
+ struct cartesian_product_view_t {
81
+ detail::view_storage<Sequences> sequences_;
82
+ using hana_tag = view_tag;
83
+ };
84
+
85
+ struct make_cartesian_product_view_t {
86
+ template <typename Sequences>
87
+ constexpr cartesian_product_view_t <Sequences> operator ()(Sequences& s) const {
88
+ return {s};
89
+ }
90
+ };
91
+
92
+ constexpr make_cartesian_product_view_t cartesian_product_view{};
93
+
94
+ template <typename Sequences>
95
+ struct is_view <cartesian_product_view_t <Sequences>> {
96
+ static constexpr bool value = true ;
97
+ };
98
+
61
99
// ////////////////////////////////////////////////////////////////////
62
100
// sliced_view
63
101
// ////////////////////////////////////////////////////////////////////
@@ -212,6 +250,33 @@ BOOST_HANA_NAMESPACE_BEGIN
212
250
// ////////////////////////////////////////////////////////////////////////
213
251
template <>
214
252
struct unpack_impl <hana::view_tag> {
253
+ // cartesian_product_element_view
254
+ template <typename Sequences, std::size_t i, typename F>
255
+ static constexpr decltype (auto )
256
+ apply(detail::cartesian_product_element_view_t <Sequences, i> view, F const & f) {
257
+ using Indices = decltype (detail::make_cartesian_product_indices (view.sequences_ ));
258
+ return hana::unpack (view.sequences_ ,
259
+ detail::make_cartesian_product_element_t <F, i>{f});
260
+ }
261
+
262
+ // cartesian_product_view
263
+ template <typename View, typename F, std::size_t ...i>
264
+ static constexpr decltype (auto )
265
+ unpack_cartesian_product(View view, F&& f, std::index_sequence<i...>) {
266
+ return static_cast <F&&>(f)(
267
+ detail::cartesian_product_element_view_t <decltype (view.sequences_ ), i>{
268
+ view.sequences_
269
+ }...);
270
+ }
271
+
272
+ template <typename Sequences, typename F>
273
+ static constexpr decltype (auto )
274
+ apply(detail::cartesian_product_view_t <Sequences> view, F&& f) {
275
+ using Indices = decltype (detail::make_cartesian_product_indices (view.sequences_ ));
276
+ return unpack_cartesian_product (view, static_cast <F&&>(f),
277
+ std::make_index_sequence<Indices::length>{});
278
+ }
279
+
215
280
// sliced_view
216
281
template <typename Sequence, std::size_t ...i, typename F>
217
282
static constexpr decltype (auto )
@@ -279,6 +344,22 @@ BOOST_HANA_NAMESPACE_BEGIN
279
344
// ////////////////////////////////////////////////////////////////////////
280
345
template <>
281
346
struct at_impl <hana::view_tag> {
347
+ // cartesian_product_element_view
348
+ template <typename Sequences, std::size_t i, typename N>
349
+ static constexpr decltype (auto )
350
+ apply(detail::cartesian_product_element_view_t <Sequences, i> view, N const &) {
351
+ using Indices = decltype (detail::make_cartesian_product_indices (view.sequences_ ));
352
+ return hana::at_c<Indices::indices_of (i)[N::value]>(
353
+ hana::at_c<N::value>(view.sequences_ ));
354
+ }
355
+
356
+ // cartesian_product_view
357
+ template <typename Sequences, typename N>
358
+ static constexpr decltype (auto )
359
+ apply(detail::cartesian_product_view_t <Sequences> view, N const &) {
360
+ return detail::cartesian_product_element_view_t <Sequences, N::value>{view.sequences_ };
361
+ }
362
+
282
363
// sliced_view
283
364
template <typename Sequence, std::size_t ...i, typename N>
284
365
static constexpr decltype (auto )
@@ -368,6 +449,19 @@ BOOST_HANA_NAMESPACE_BEGIN
368
449
369
450
template <>
370
451
struct length_impl <hana::view_tag> {
452
+ // cartesian_product_view_element
453
+ template <typename Sequences, std::size_t i>
454
+ static constexpr auto apply (detail::cartesian_product_element_view_t <Sequences, i> view) {
455
+ return hana::length (view.sequences_ );
456
+ }
457
+
458
+ // cartesian_product_view
459
+ template <typename Sequences>
460
+ static constexpr auto apply (detail::cartesian_product_view_t <Sequences> view) {
461
+ using Indices = decltype (detail::make_cartesian_product_indices (view.sequences_ ));
462
+ return hana::size_c<Indices::length>;
463
+ }
464
+
371
465
// sliced_view
372
466
template <typename Sequence, std::size_t ...i>
373
467
static constexpr auto
@@ -394,11 +488,12 @@ BOOST_HANA_NAMESPACE_BEGIN
394
488
struct sum_lengths {
395
489
template <typename ...S>
396
490
constexpr auto operator ()(S const & ...s) const {
397
- constexpr std::size_t lengths[] = {decltype (hana::length (s))::value...};
491
+ constexpr std::size_t lengths[sizeof ...(S) ] = {decltype (hana::length (s))::value...};
398
492
constexpr std::size_t sum = detail::accumulate (lengths, lengths+sizeof ...(S), 0 );
399
493
return hana::size_t <sum>{};
400
494
}
401
495
};
496
+
402
497
template <typename Sequences>
403
498
static constexpr auto apply (detail::flattened_view_t <Sequences> view) {
404
499
return hana::unpack (view.sequences_ , sum_lengths{});
@@ -424,6 +519,20 @@ BOOST_HANA_NAMESPACE_BEGIN
424
519
425
520
template <>
426
521
struct is_empty_impl <hana::view_tag> {
522
+ // cartesian_product_view_element
523
+ template <typename Sequences, std::size_t i>
524
+ static constexpr auto apply (detail::cartesian_product_element_view_t <Sequences, i> view) {
525
+ using Indices = decltype (detail::make_cartesian_product_indices (view.sequences_ ));
526
+ return hana::bool_c<Indices::length == 0 >;
527
+ }
528
+
529
+ // cartesian_product_view
530
+ template <typename Sequences>
531
+ static constexpr auto apply (detail::cartesian_product_view_t <Sequences> view) {
532
+ using Indices = decltype (detail::make_cartesian_product_indices (view.sequences_ ));
533
+ return hana::bool_c<Indices::length == 0 >;
534
+ }
535
+
427
536
// sliced_view
428
537
template <typename Sequence, std::size_t ...i>
429
538
static constexpr auto
0 commit comments