orx_meta/queue/
define_queue.rs

1/// [orx_meta](https://crates.io/crates/orx-meta) crate defines statically-typed queues with heterogeneous elements.
2/// See [`StQueue`], [`QueueSingle`] and [`Queue`].
3/// Further, it provides the [`QueueBuilder`] as a generic builder for complex types and [`queue_of`] for conveniently
4/// aliasing complex queue types.
5///
6/// These are useful for several use cases; however, not sufficient for zero-cost abstraction.
7/// For more information, please see
8/// * examples [3_composition_idea](https://github.com/orxfun/orx-meta/blob/main/docs/3_composition_idea.md)
9///   and [5_solution_with_macros](https://github.com/orxfun/orx-meta/blob/main/docs/5_solution_with_macros.md); and
10/// * the article [zero cost composition](https://orxfun.github.io/orxfun-notes/#/zero-cost-composition-2025-10-15).
11///
12/// The `define_macro` allows us to re-create all above-mentioned queue types and code with the following additions:
13/// * Queue types might have custom generic parameters, and/or lifetime parameters.
14/// * But most importantly, we can limit elements that can be included in the queue with a custom trait or traits.
15///   In other words, we can add trait bounds to elements that can be pushed to the queue. This allows us to achieve
16///   zero-cost composition.
17///
18/// # Example - Recreating and Renaming
19///
20/// The following is the simplest usage of this macro.
21///
22/// ```
23/// orx_meta::define_queue!(
24///     queue => [ MyQueue ; MySingleQueue, MyMultiQueue ];
25/// );
26///
27/// let queue = MyMultiQueue::new(42).push(true).push('x');
28/// assert_eq!(queue.as_tuple(), (&42, &true, &'x'));
29/// ```
30/// It just recreates [`StQueue`] trait with name `MyQueue`, [`QueueSingle`] implementation as `MySingleQueue` and
31/// [`Queue`] implementation as `MyMultiQueue`.
32///
33/// Everything will be the same other than renaming.
34///
35/// Notice that defining the queue builder and `queue_of` macro are optional. In the following, we also define these
36/// again with new names `MyQueueBuilder` and `q_of`.
37///
38/// ```
39/// orx_meta::define_queue!(
40///     queue => [ MyQueue ; MySingleQueue, MyMultiQueue ];
41///     queue_of => q_of;
42///     builder => MyQueueBuilder;
43/// );
44///
45/// let queue = MyQueueBuilder::<q_of!(u32, bool, char)>::new().push(42).push(true).push('x').finish();
46/// assert_eq!(queue.as_tuple(), (&42, &true, &'x'));
47/// ```
48///
49/// # Example - Trait Bounds
50///
51/// The main purpose of this macro; however, is to add trait bounds to the elements that can be contained by the queue.
52///
53/// Assume for instance, we want all our elements to implement the `Draw` trait.
54///
55/// We can define this by providing the `elements => [Draw]` block to the macro. Note that we can define a comma-separated
56/// list of traits within the brackets.
57///
58/// In addition to elements of the queue, the design requires the queue types to implement the `Draw` trait as well.
59/// This is the central idea of zero-composition.
60///
61/// Since there are two implementations of the queue, we need to implement `Draw` for these two types:
62/// * Single-element queue: This is a trivial implementation. Since the queue contains only one element which implements
63///   `Draw`, it exhibits the behavior of that element. This is the **identity**.
64/// * Multi-element queue: Here, the queue contains at least two elements. All elements implement `Draw`. We need to define
65///   what the draw behavior must be whenever there are multiple elements. This is the **composition**.
66///
67/// The following provides the entire example.
68///
69/// ```
70/// // draw
71///
72/// pub trait Draw {
73///     fn draw(&self);
74/// }
75///
76/// // example Draw components
77///
78/// #[derive(Debug)]
79/// pub struct Button {
80///     pub width: u32,
81///     pub height: u32,
82///     pub label: String,
83/// }
84///
85/// impl Draw for Button {
86///     fn draw(&self) {
87///         println!("{self:?}");
88///     }
89/// }
90///
91/// #[derive(Debug)]
92/// #[allow(dead_code)]
93/// struct SelectBox {
94///     pub width: u32,
95///     pub height: u32,
96///     pub options: Vec<String>,
97/// }
98///
99/// impl Draw for SelectBox {
100///     fn draw(&self) {
101///         println!("{self:?}");
102///     }
103/// }
104///
105/// // queue definition
106///
107/// orx_meta::define_queue!(
108///     elements => [ Draw ];
109///     queue => [ StScreen ; ScreenSingle, Screen ];
110/// );
111///
112/// impl<F: Draw> Draw for ScreenSingle<F> {
113///     fn draw(&self) {
114///         self.f.draw();
115///     }
116/// }
117///
118/// impl<F, B> Draw for Screen<F, B>
119/// where
120///     F: Draw,
121///     B: StScreen,
122/// {
123///     fn draw(&self) {
124///         self.f.draw();
125///         self.b.draw();
126///     }
127/// }
128///
129/// let screen = Screen::new(Button {
130///     width: 3,
131///     height: 4,
132///     label: String::from("login"),
133/// })
134/// .push(Button {
135///     width: 4,
136///     height: 5,
137///     label: String::from("logout"),
138/// })
139/// .push(SelectBox {
140///     width: 10,
141///     height: 6,
142///     options: vec![String::from("This"), String::from("that")],
143/// });
144/// screen.draw();
145///
146/// // prints out:
147/// //
148/// // Button { width: 3, height: 4, label: "login" }
149/// // Button { width: 4, height: 5, label: "logout" }
150/// // SelectBox { width: 10, height: 6, options: ["This", "that"] }
151/// ```
152///
153///
154///
155///
156///
157///
158/// [`StQueue`]: crate::queue::StQueue
159/// [`QueueSingle`]: crate::queue::QueueSingle
160/// [`Queue`]: crate::queue::Queue
161/// [`QueueBuilder`]: crate::queue::QueueBuilder
162/// [`queue_of`]: crate::queue_of
163#[macro_export]
164macro_rules! define_queue {
165    (
166        lt => [$($g_lt:tt), *];
167        generics => [ $( $g:tt $( : $( $g_bnd:ident $( < $( $g_bnd_g:tt ),* > )? )| * )? ), * ];
168        elements => [ $( $el_bnd:ident $( < $( $el_bnd_g:tt ),* > )? )| * ];
169        queue => [$q:ident ; $empty:ident, $pair:ident];
170
171        queue_of => $queue_of:ident;
172        builder => $builder:ident;
173    ) => {
174        $crate::define_queue_core!(
175            lt => [$($g_lt), *];
176            generics => [ $( $g $( : $( $g_bnd $( < $( $g_bnd_g ),* > )? )| * )? ), * ];
177            elements => [ $( $el_bnd $( < $( $el_bnd_g ),* > )? )| * ];
178            queue => [$q ; $empty, $pair];
179        );
180        $crate::define_queue_of!(
181            lt => [$($g_lt), *];
182            generics => [ $( $g $( : $( $g_bnd $( < $( $g_bnd_g ),* > )? )| * )? ), * ];
183            queue => [$q ; $empty, $pair];
184            queue_of => $queue_of;
185        );
186
187        $crate::define_queue_builder!(
188            lt => [$($g_lt), *];
189            generics => [ $( $g $( : $( $g_bnd $( < $( $g_bnd_g ),* > )? )| * )? ), * ];
190            queue => [$q ; $empty, $pair];
191            builder => $builder;
192        );
193
194        $crate::define_nonempty_queue_tuple_transformation!(
195            lt => [$($g_lt), *];
196            generics => [ $( $g $( : $( $g_bnd $( < $( $g_bnd_g ),* > )? )| * )? ), * ];
197            elements => [ $( $el_bnd $( < $( $el_bnd_g ),* > )? )| * ];
198            queue => [$q ; $empty, $pair];
199        );
200    };
201
202    // core
203    (
204        queue => [$q:ident ; $empty:ident, $pair:ident];
205    ) => {
206        $crate::define_queue_core!(
207            lt => [];
208            generics => [];
209            elements => [];
210            queue => [$q ; $empty, $pair];
211        );
212        $crate::define_nonempty_queue_tuple_transformation!(
213            lt => [];
214            generics => [];
215            elements => [];
216            queue => [$q ; $empty, $pair];
217        );
218    };
219
220    // core - elements
221    (
222        elements => [ $( $el_bnd:ident $( < $( $el_bnd_g:tt ),* > )? )| * ];
223        queue => [$q:ident ; $empty:ident, $pair:ident];
224    ) => {
225        $crate::define_queue_core!(
226            lt => [];
227            generics => [];
228            elements => [ $( $el_bnd $( < $( $el_bnd_g ),* > )? )| * ];
229            queue => [$q ; $empty, $pair];
230        );
231        $crate::define_nonempty_queue_tuple_transformation!(
232            lt => [];
233            generics => [];
234            elements => [ $( $el_bnd $( < $( $el_bnd_g ),* > )? )| * ];
235            queue => [$q ; $empty, $pair];
236        );
237    };
238
239    // core - lifetime elements
240    (
241        lt => [$($g_lt:tt), *];
242        elements => [ $( $el_bnd:ident $( < $( $el_bnd_g:tt ),* > )? )| * ];
243        queue => [$q:ident ; $empty:ident, $pair:ident];
244    ) => {
245        $crate::define_queue_core!(
246            lt => [$($g_lt), *];
247            generics => [];
248            elements => [ $( $el_bnd $( < $( $el_bnd_g ),* > )? )| * ];
249            queue => [$q ; $empty, $pair];
250        );
251        $crate::define_nonempty_queue_tuple_transformation!(
252            lt => [$($g_lt), *];
253            generics => [];
254            elements => [ $( $el_bnd $( < $( $el_bnd_g ),* > )? )| * ];
255            queue => [$q ; $empty, $pair];
256        );
257    };
258
259    // # queue_of
260
261    // core
262    (
263        queue => [$q:ident ; $empty:ident, $pair:ident];
264        queue_of => $queue_of:ident;
265    ) => {
266        $crate::define_queue_core!(
267            lt => [];
268            generics => [];
269            elements => [];
270            queue => [$q ; $empty, $pair];
271        );
272        $crate::define_nonempty_queue_tuple_transformation!(
273            lt => [];
274            generics => [];
275            elements => [];
276            queue => [$q ; $empty, $pair];
277        );
278        $crate::define_queue_of!(
279            lt => [];
280            generics => [];
281            queue => [$q ; $empty, $pair];
282            queue_of => $queue_of;
283        );
284    };
285
286    // core - elements
287    (
288        elements => [ $( $el_bnd:ident $( < $( $el_bnd_g:tt ),* > )? )| * ];
289        queue => [$q:ident ; $empty:ident, $pair:ident];
290        queue_of => $queue_of:ident;
291    ) => {
292        $crate::define_queue_core!(
293            lt => [];
294            generics => [];
295            elements => [ $( $el_bnd $( < $( $el_bnd_g ),* > )? )| * ];
296            queue => [$q ; $empty, $pair];
297        );
298        $crate::define_nonempty_queue_tuple_transformation!(
299            lt => [];
300            generics => [ ];
301            elements => [ $( $el_bnd $( < $( $el_bnd_g ),* > )? )| * ];
302            queue => [$q ; $empty, $pair];
303        );
304        $crate::define_queue_of!(
305            lt => [];
306            generics => [];
307            queue => [$q ; $empty, $pair];
308            queue_of => $queue_of;
309        );
310    };
311
312    // core - lifetime elements
313    (
314        lt => [$($g_lt:tt), *];
315        elements => [ $( $el_bnd:ident $( < $( $el_bnd_g:tt ),* > )? )| * ];
316        queue => [$q:ident ; $empty:ident, $pair:ident];
317        queue_of => $queue_of:ident;
318    ) => {
319        $crate::define_queue_core!(
320            lt => [$($g_lt), *];
321            generics => [];
322            elements => [ $( $el_bnd $( < $( $el_bnd_g ),* > )? )| * ];
323            queue => [$q ; $empty, $pair];
324        );
325        $crate::define_nonempty_queue_tuple_transformation!(
326            lt => [$($g_lt), *];
327            generics => [];
328            elements => [ $( $el_bnd $( < $( $el_bnd_g ),* > )? )| * ];
329            queue => [$q ; $empty, $pair];
330        );
331        $crate::define_queue_of!(
332            lt => [$($g_lt), *];
333            generics => [];
334            queue => [$q ; $empty, $pair];
335            queue_of => $queue_of;
336        );
337    };
338
339    // # builder
340
341    // core
342    (
343        queue => [$q:ident ; $empty:ident, $pair:ident];
344        builder => $builder:ident;
345    ) => {
346        $crate::define_queue_core!(
347            lt => [];
348            generics => [];
349            elements => [];
350            queue => [$q ; $empty, $pair];
351        );
352        $crate::define_nonempty_queue_tuple_transformation!(
353            lt => [];
354            generics => [];
355            elements => [];
356            queue => [$q ; $empty, $pair];
357        );
358        $crate::define_queue_builder!(
359            lt => [];
360            generics => [];
361            queue => [$q ; $empty, $pair];
362            builder => $builder;
363        );
364    };
365
366    // core - elements
367    (
368        elements => [ $( $el_bnd:ident $( < $( $el_bnd_g:tt ),* > )? )| * ];
369        queue => [$q:ident ; $empty:ident, $pair:ident];
370        builder => $builder:ident;
371    ) => {
372        $crate::define_queue_core!(
373            lt => [];
374            generics => [];
375            elements => [ $( $el_bnd $( < $( $el_bnd_g ),* > )? )| * ];
376            queue => [$q ; $empty, $pair];
377        );
378        $crate::define_nonempty_queue_tuple_transformation!(
379            lt => [];
380            generics => [];
381            elements => [ $( $el_bnd $( < $( $el_bnd_g ),* > )? )| * ];
382            queue => [$q ; $empty, $pair];
383        );
384        $crate::define_queue_builder!(
385            lt => [];
386            generics => [];
387            queue => [$q ; $empty, $pair];
388            builder => $builder;
389        );
390    };
391
392    // core - lifetime elements
393    (
394        lt => [$($g_lt:tt), *];
395        elements => [ $( $el_bnd:ident $( < $( $el_bnd_g:tt ),* > )? )| * ];
396        queue => [$q:ident ; $empty:ident, $pair:ident];
397        builder => $builder:ident;
398    ) => {
399        $crate::define_queue_core!(
400            lt => [$($g_lt), *];
401            generics => [];
402            elements => [ $( $el_bnd $( < $( $el_bnd_g ),* > )? )| * ];
403            queue => [$q ; $empty, $pair];
404        );
405        $crate::define_nonempty_queue_tuple_transformation!(
406            lt => [$($g_lt), *];
407            generics => [];
408            elements => [ $( $el_bnd $( < $( $el_bnd_g ),* > )? )| * ];
409            queue => [$q ; $empty, $pair];
410        );
411        $crate::define_queue_builder!(
412            lt => [$($g_lt), *];
413            generics => [];
414            queue => [$q ; $empty, $pair];
415            builder => $builder;
416        );
417    };
418
419    // # queue_of + builder
420
421    // core
422    (
423        queue => [$q:ident ; $empty:ident, $pair:ident];
424        queue_of => $queue_of:ident;
425        builder => $builder:ident;
426    ) => {
427        $crate::define_queue_core!(
428            lt => [];
429            generics => [];
430            elements => [];
431            queue => [$q ; $empty, $pair];
432        );
433        $crate::define_nonempty_queue_tuple_transformation!(
434            lt => [];
435            generics => [];
436            elements => [];
437            queue => [$q ; $empty, $pair];
438        );
439        $crate::define_queue_of!(
440            lt => [];
441            generics => [];
442            queue => [$q ; $empty, $pair];
443            queue_of => $queue_of;
444        );
445        $crate::define_queue_builder!(
446            lt => [];
447            generics => [];
448            queue => [$q ; $empty, $pair];
449            builder => $builder;
450        );
451    };
452
453    // core - elements
454    (
455        elements => [ $( $el_bnd:ident $( < $( $el_bnd_g:tt ),* > )? )| * ];
456        queue => [$q:ident ; $empty:ident, $pair:ident];
457        queue_of => $queue_of:ident;
458        builder => $builder:ident;
459    ) => {
460        $crate::define_queue_core!(
461            lt => [];
462            generics => [];
463            elements => [ $( $el_bnd $( < $( $el_bnd_g ),* > )? )| * ];
464            queue => [$q ; $empty, $pair];
465        );
466        $crate::define_nonempty_queue_tuple_transformation!(
467            lt => [];
468            generics => [];
469            elements => [ $( $el_bnd $( < $( $el_bnd_g ),* > )? )| * ];
470            queue => [$q ; $empty, $pair];
471        );
472        $crate::define_queue_of!(
473            lt => [];
474            generics => [];
475            queue => [$q ; $empty, $pair];
476            queue_of => $queue_of;
477        );
478        $crate::define_queue_builder!(
479            lt => [];
480            generics => [];
481            queue => [$q ; $empty, $pair];
482            builder => $builder;
483        );
484    };
485
486    // core - lifetime elements
487    (
488        lt => [$($g_lt:tt), *];
489        elements => [ $( $el_bnd:ident $( < $( $el_bnd_g:tt ),* > )? )| * ];
490        queue => [$q:ident ; $empty:ident, $pair:ident];
491        queue_of => $queue_of:ident;
492        builder => $builder:ident;
493    ) => {
494        $crate::define_queue_core!(
495            lt => [$($g_lt), *];
496            generics => [];
497            elements => [ $( $el_bnd $( < $( $el_bnd_g ),* > )? )| * ];
498            queue => [$q ; $empty, $pair];
499        );
500        $crate::define_nonempty_queue_tuple_transformation!(
501            lt => [$($g_lt), *];
502            generics => [];
503            elements => [ $( $el_bnd $( < $( $el_bnd_g ),* > )? )| * ];
504            queue => [$q ; $empty, $pair];
505        );
506        $crate::define_queue_of!(
507            lt => [$($g_lt), *];
508            generics => [];
509            queue => [$q ; $empty, $pair];
510            queue_of => $queue_of;
511        );
512        $crate::define_queue_builder!(
513            lt => [$($g_lt), *];
514            generics => [];
515            queue => [$q ; $empty, $pair];
516            builder => $builder;
517        );
518    };
519}
520
521// # 1. core
522
523#[doc(hidden)]
524#[macro_export]
525macro_rules! define_queue_core {
526    (
527        lt => [$($g_lt:tt), *];
528        generics => [ $( $g:tt $( : $( $g_bnd:ident $( < $( $g_bnd_g:tt ),* > )? )| * )? ), * ];
529        elements => [ $( $el_bnd:ident $( < $( $el_bnd_g:tt ),* > )? )| * ];
530        queue => [$q:ident ; $empty:ident, $pair:ident];
531    ) => {
532        /// A strongly typed non-empty queue of heterogeneous elements.
533        ///
534        /// There exist two implementations:
535        /// * [`QueueSingle`] which includes exactly one element, and
536        /// * [`Queue`] containing multiple (>=2) elements.
537        ///
538        /// Also see [`define_queue`] macro to define a queue of heterogeneous elements
539        /// all of which exhibit a common behavior, or implement a common set of traits.
540        /// For more information, please see
541        /// * examples [3_composition_idea](https://github.com/orxfun/orx-meta/blob/main/docs/3_composition_idea.md)
542        ///   and [5_solution_with_macros](https://github.com/orxfun/orx-meta/blob/main/docs/5_solution_with_macros.md); and
543        /// * the article [zero cost composition](https://orxfun.github.io/orxfun-notes/#/zero-cost-composition-2025-10-15).
544        ///
545        /// [`define_queue`]: crate::define_queue
546        /// [`QueueSingle`]: crate::queue::QueueSingle
547        /// [`Queue`]: crate::queue::Queue
548        #[allow(dead_code)]
549        #[allow(clippy::len_without_is_empty)]
550        pub trait $q<$($g_lt ,)* $($g ,)*>
551        where
552            Self: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
553            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
554        {
555            /// Type of the queue obtained by adding an element of type `Elem` to this queue.
556            type PushBack<T>: $q<$($g_lt ,)* $($g ,)*>
557            where
558                T: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *;
559
560            /// Type of the element at the front of the queue.
561            type Front: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *;
562
563            /// Type of the queue that would be obtained by popping the `Front` element of the queue.
564            type Back: $q<$($g_lt ,)* $($g ,)*>;
565
566            /// Number of elements in the queue.
567            const LEN: usize;
568
569            /// Pushes the `element` and returns the resulting queue.
570            ///
571            /// *Type of the resulting queue is known by the generic associated type `Self::PushBack<Elem>`.*
572            ///
573            /// # Examples
574            ///
575            /// ```ignore
576            /// use orx_meta::queue::*;
577            ///
578            /// let queue = Queue::new(42);
579            /// assert_eq!(queue.as_tuple(), &42);
580            ///
581            /// let queue = Queue::new(42).push(true).push('x');
582            /// assert_eq!(queue.as_tuple(), (&42, &true, &'x'));
583            ///
584            /// let queue = queue.push("foo");
585            /// assert_eq!(queue.as_tuple(), (&42, &true, &'x', &"foo"));
586            /// ```
587            fn push<T>(self, x: T) -> Self::PushBack<T>
588            where
589                T: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *;
590
591            /// Pushes the `element` and returns the resulting queue.
592            ///
593            /// *This method is provided for convention. Length of the queue is actually known by the constant `Self::LEN`.*
594            ///
595            /// # Examples
596            ///
597            /// ```ignore
598            /// use orx_meta::queue::*;
599            ///
600            /// let queue = Queue::new(42);
601            /// assert_eq!(queue.len(), 1);
602            ///
603            /// let queue = Queue::new(42).push(true).push('x');
604            /// assert_eq!(queue.len(), 3);
605            ///
606            /// let (num, queue) = queue.pop();
607            /// assert_eq!(num, 42);
608            /// assert_eq!(queue.len(), 2);
609            ///
610            /// let queue = queue.push(true);
611            /// assert_eq!(queue.len(), 3);
612            /// ```
613            #[inline(always)]
614            fn len(&self) -> usize {
615                Self::LEN
616            }
617
618            /// Returns a reference to the element in the front of the queue.
619            ///
620            /// # Examples
621            ///
622            /// ```ignore
623            /// use orx_meta::queue::*;
624            ///
625            /// let queue = Queue::new(42);
626            /// assert_eq!(queue.front(), &42);
627            ///
628            /// let queue = Queue::new(42).push(true).push('x').push("foo");
629            /// assert_eq!(queue.front(), &42);
630            ///
631            /// let (num, queue) = queue.pop();
632            /// assert_eq!(num, 42);
633            /// assert_eq!(queue.front(), &true);
634            ///
635            /// let (flag, queue) = queue.pop();
636            /// assert_eq!(flag, true);
637            /// assert_eq!(queue.front(), &'x');
638            ///
639            /// let (c, queue) = queue.pop();
640            /// assert_eq!(c, 'x');
641            /// assert_eq!(queue.front(), &"foo");
642            ///
643            /// let s = queue.pop();
644            /// assert_eq!(s, "foo");
645            /// ```
646            fn front(&self) -> &Self::Front;
647
648            /// Returns a mutable reference to the element in the front of the queue.
649            ///
650            /// # Examples
651            ///
652            /// ```ignore
653            /// use orx_meta::queue::*;
654            ///
655            /// let mut queue = Queue::new(42).push(true).push('x');
656            ///
657            /// *queue.front_mut() *= 2;
658            /// *queue.back_mut().front_mut() = false;
659            /// *queue.back_mut().back_mut().front_mut() = 'y';
660            ///
661            /// assert_eq!(queue.as_tuple(), (&84, &false, &'y'));
662            /// ```
663            fn front_mut(&mut self) -> &mut Self::Front;
664
665            /// Consumes the queue and returns the element in the front of the queue.
666            ///
667            /// # Examples
668            ///
669            /// ```ignore
670            /// use orx_meta::queue::*;
671            ///
672            /// let queue = Queue::new(42);
673            /// assert_eq!(queue.into_front(), 42);
674            ///
675            /// let queue = Queue::new(42).push(true).push('x').push("foo".to_string());
676            /// assert_eq!(queue.into_front(), 42);
677            ///
678            /// let queue = Queue::new(42).push(true).push('x').push("foo".to_string());
679            /// let (num, queue) = queue.pop();
680            /// assert_eq!(num, 42);
681            /// let (flag, queue) = queue.pop();
682            /// assert_eq!(flag, true);
683            ///
684            /// assert_eq!(queue.into_front(), 'x');
685            /// ```
686            fn into_front(self) -> Self::Front;
687        }
688
689        // # single
690
691
692        /// A statically-typed queue containing exactly one element of type `Front`.
693        ///
694        /// See also the other [`StQueue`] implementation [`Queue`] which can be
695        /// created by pushing a second element to this queue.
696        #[derive(Clone, Copy, PartialEq, Eq)]
697        pub struct $empty<$($g_lt ,)* $($g ,)* Front>
698        where
699            Front: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
700            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
701        {
702            phantom: core::marker::PhantomData<$(&$g_lt)* ($($g ,)*)>,
703            f: Front,
704        }
705
706        impl<$($g_lt ,)* F, $($g ,)*> $empty<$($g_lt ,)* $($g ,)* F>
707        where
708            F: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
709            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
710        {
711            /// Creates a new statically-typed queue [`StQueue`] containing exactly one `element`.
712            ///
713            /// Alternatively, we can use multiple element queue's [`new`]. This is for convenience to
714            /// allows to work with a single queue type while coding.
715            ///
716            /// [`new`]: crate::queue::Queue::new
717            ///
718            /// # Examples
719            ///
720            /// ```ignore
721            /// use orx_meta::queue::*;
722            ///
723            /// let queue: QueueSingle<u32> = QueueSingle::new(42);
724            /// assert_eq!(queue.len(), 1);
725            /// assert_eq!(queue.front(), &42);
726            ///
727            /// // alternatively, we can use `Queue::new`:
728            /// let queue: QueueSingle<u32> = Queue::new(42);
729            /// assert_eq!(queue.len(), 1);
730            /// assert_eq!(queue.front(), &42);
731            /// ```
732            #[inline(always)]
733            pub fn new(element: F) -> Self {
734                Self {
735                    phantom: Default::default(),
736                    f: element,
737                }
738            }
739
740            /// Pops and returns the element in the front of this queue.
741            ///
742            /// Since this element contains only one element, there is no remaining queue once the
743            /// front is popped. Therefore, the return type is only the element rather than a tuple.
744            ///
745            /// # Examples
746            ///
747            /// ```ignore
748            /// use orx_meta::queue::*;
749            ///
750            /// let queue: QueueSingle<u32> = QueueSingle::new(42);
751            ///
752            /// let num = queue.pop();
753            /// assert_eq!(num, 42);
754            /// ```
755            #[inline(always)]
756            pub fn pop(self) -> F {
757                self.f
758            }
759        }
760
761        impl<$($g_lt ,)* F, $($g ,)*> core::fmt::Debug for $empty<$($g_lt ,)* $($g ,)* F>
762        where
763            F: core::fmt::Debug,
764            F: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
765            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
766        {
767            fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
768                write!(f, "{}({:?})", stringify!($empty), self.f)
769            }
770        }
771
772        impl<$($g_lt ,)* F, $($g ,)*> $q<$($g_lt ,)* $($g ,)*> for $empty<$($g_lt ,)* $($g ,)* F>
773        where
774            F: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
775            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
776        {
777            type PushBack<Elem> = $pair<$($g_lt ,)* $($g ,)* F, $empty<$($g_lt ,)* $($g ,)* Elem>>
778            where
779                Elem: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *;
780
781            type Front = F;
782
783            type Back = Self;
784
785            const LEN: usize = 1;
786
787            #[inline(always)]
788            fn push<Elem>(self, x: Elem) -> Self::PushBack<Elem>
789            where
790                Elem: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *
791            {
792                $pair::from_fb(self.f, $empty::new(x))
793            }
794
795            #[inline(always)]
796            fn front(&self) -> &Self::Front {
797                &self.f
798            }
799
800            #[inline(always)]
801            fn front_mut(&mut self) -> &mut Self::Front {
802                &mut self.f
803            }
804
805            #[inline(always)]
806            fn into_front(self) -> Self::Front {
807                self.f
808            }
809        }
810
811        // # pair
812
813        /// A queue containing multiple (>= 2) elements.
814        ///
815        /// It is composed of two parts:
816        /// * `f: Front` is the element in the front of the queue;
817        /// * `b: Back` is the queue of remaining elements except for the one in the front.
818        ///   It can be:
819        ///   * either a [`QueueSingle`] containing exactly one element in which case length of this
820        ///     queue is 2,
821        ///   * or a [`Queue`] containing multiple elements, in which case length of this queue is
822        ///     greater than 2, `1 + self.b.len()`.
823        ///
824        /// Note that `Queue::new(element)` gives a `QueueSingle` with one element. In order to create
825        /// a queue of multiple elements, we need to push at least one more element, such as
826        /// `Queue::new(elem1).push(elem2)`.
827        #[derive(Clone, Copy, PartialEq, Eq)]
828        pub struct $pair<$($g_lt ,)* $($g ,)* Front, Back>
829        where
830            Front: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
831            Back: $q<$($g_lt ,)* $($g ,)*>,
832            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
833        {
834            phantom: core::marker::PhantomData<$(&$g_lt)* ($($g ,)*)>,
835            f: Front,
836            b: Back,
837        }
838
839        impl<$($g_lt ,)* F, $($g ,)*> $pair<$($g_lt ,)* $($g ,)* F, $empty<$($g_lt ,)* $($g ,)* F>>
840        where
841            F: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
842            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
843        {
844            /// Creates a [`QueueSingle`] with exactly one `element`.
845            ///
846            /// Note that `Queue::new` is equivalent to `QueueSingle::new`. It is introduced for
847            /// convenience allowing us to work only with the multiple element queue type `Queue`.
848            ///
849            /// # Examples
850            ///
851            /// ```ignore
852            /// use orx_meta::queue::*;
853            /// use orx_meta::queue_of;
854            ///
855            /// // creates a QueueSingle
856            /// let queue: QueueSingle<u32> = Queue::new(42);
857            /// assert_eq!(queue.len(), 1);
858            /// assert_eq!(queue.front(), &42);
859            ///
860            /// // creates a Queue when we push at least one more element
861            /// let queue: Queue<u32, QueueSingle<char>> = Queue::new(42).push('x');
862            /// assert_eq!(queue.len(), 2);
863            ///
864            /// let queue: Queue<u32, Queue<char, Queue<bool, QueueSingle<String>>>>
865            ///   = Queue::new(42).push('x').push(true).push("foo".to_string());
866            /// assert_eq!(queue.as_tuple(), (&42, &'x', &true, &"foo".to_string()));
867            ///
868            /// // equivalently, we can use the queue_of macro to create the type
869            /// let queue: queue_of!(u32, char, bool, String)
870            ///   = Queue::new(42).push('x').push(true).push("foo".to_string());
871            /// assert_eq!(queue.as_tuple(), (&42, &'x', &true, &"foo".to_string()));
872            /// ```
873            #[allow(clippy::new_ret_no_self)]
874            #[inline(always)]
875            pub fn new(element: F) -> $empty<$($g_lt ,)* $($g ,)* F> {
876                $empty::new(element)
877            }
878        }
879
880        impl<$($g_lt ,)* F, B, $($g ,)*> $pair<$($g_lt ,)* $($g ,)* F, B>
881        where
882            F: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
883            B: $q<$($g_lt ,)* $($g ,)*>,
884            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
885        {
886            #[inline(always)]
887            fn from_fb(f: F, b: B) -> Self {
888                Self {
889                    phantom: Default::default(),
890                    f,
891                    b,
892                }
893            }
894
895            // ref
896
897            /// Returns a reference to the queue including elements of this queue
898            /// excluding the element in the front.
899            ///
900            /// Note that accessing elements of the queue is always by `front`, while
901            /// `back` allows to access elements in all positions of the queue.
902            ///
903            /// # Examples
904            ///
905            /// ```ignore
906            /// use orx_meta::queue::*;
907            ///
908            /// let queue = Queue::new(42);
909            /// assert_eq!(queue.front(), &42);
910            /// // assert_eq!(queue.back(), ??); // wont' compile, QueueSingle has no back
911            ///
912            /// let queue = Queue::new(42).push(true).push('x').push("foo");
913            /// assert_eq!(queue.back(), &Queue::new(true).push('x').push("foo"));
914            /// assert_eq!(queue.front(), &42);
915            /// assert_eq!(queue.back().front(), &true);
916            /// assert_eq!(queue.back().back().front(), &'x');
917            /// assert_eq!(queue.back().back().back().front(), &"foo");
918            ///
919            /// let (num, queue) = queue.pop();
920            /// assert_eq!(num, 42);
921            /// assert_eq!(queue.front(), &true);
922            /// assert_eq!(queue.back(), &Queue::new('x').push("foo"));
923            ///
924            /// let (flag, queue) = queue.pop();
925            /// assert_eq!(flag, true);
926            /// assert_eq!(queue.front(), &'x');
927            /// assert_eq!(queue.back(), &Queue::new("foo"));
928            ///
929            /// let (c, queue) = queue.pop();
930            /// assert_eq!(c, 'x');
931            /// assert_eq!(queue.front(), &"foo");
932            /// // assert_eq!(queue.back(), ??);  // wont' compile, QueueSingle has no back
933            ///
934            /// let s = queue.pop();
935            /// assert_eq!(s, "foo");
936            /// ```
937            pub fn back(&self) -> &B {
938                &self.b
939            }
940
941            // mut
942
943            /// Returns a mutable reference to the queue including elements of this queue
944            /// excluding the element in the front.
945            ///
946            /// Note that mutating elements of the queue is always by `front_mut`, while
947            /// `back_mut` allows to access elements in all positions of the queue.
948            ///
949            /// # Examples
950            ///
951            /// ```ignore
952            /// use orx_meta::queue::*;
953            ///
954            /// let mut queue = Queue::new(42).push(true).push('x');
955            ///
956            /// *queue.front_mut() *= 2;
957            /// *queue.back_mut().front_mut() = false;
958            /// *queue.back_mut().back_mut().front_mut() = 'y';
959            ///
960            /// assert_eq!(queue.as_tuple(), (&84, &false, &'y'));
961            /// ```
962            pub fn back_mut(&mut self) -> &mut B {
963                &mut self.b
964            }
965
966            /// Returns a pair of mutable references:
967            /// * first to the element in the front of the queue, and
968            /// * second to the back queue containing elements except for the front.
969            ///
970            /// # Safety
971            ///
972            /// Assume we have a queue of three elements and we want to mutate the first and
973            /// third elements as follows.
974            ///
975            /// However, the following code would not compile.
976            ///
977            /// ```compile_fail ignore
978            /// use orx_meta::queue::*;
979            ///
980            /// let mut q = Queue::new(3).push(true).push('x');
981            ///
982            /// let first = q.front_mut();
983            /// let third = q.back_mut().back_mut().front_mut();
984            ///
985            /// // these calls can be made concurrently
986            /// *first *= 2;
987            /// *third = 'y';
988            /// ```
989            ///
990            /// It is perfectly safe to mutate the first and third elements at the same time.
991            /// Actually, we can mutate all of the elements concurrently.
992            ///
993            /// However, we need to help the compiler to figure this out, which is why we get
994            /// the mutable references to the front and back at the same time. With this, the
995            /// compiler understands that there is no overlap between them.
996            ///
997            /// # Examples
998            ///
999            /// So the following code would compile and work expectedly.
1000            ///
1001            /// ```ignore
1002            /// use orx_meta::queue::*;
1003            ///
1004            /// let mut q = Queue::new(3).push(true).push('x');
1005            ///
1006            /// let (first, q23) = q.front_back_mut();
1007            /// let third = q23.back_mut().front_mut();
1008            ///
1009            /// // these calls can be made concurrently
1010            /// *first *= 2;
1011            /// *third = 'y';
1012            ///
1013            /// assert_eq!(q.as_tuple(), (&6, &true, &'y'));
1014            /// ```
1015            pub fn front_back_mut(&mut self) -> (&mut F, &mut B) {
1016                (&mut self.f, &mut self.b)
1017            }
1018
1019            // into
1020
1021            /// Consumes the queue and returns the queue including elements of this queue
1022            /// except for the element in the front.
1023            ///
1024            /// Equivalent to `queue.pop().1`.
1025            pub fn into_back(self) -> B {
1026                self.b
1027            }
1028
1029            /// Consumes the queue and returns the tuple of its front and back:
1030            ///
1031            /// * **front** is the element in the front of this queue.
1032            /// * **back** is the queue including all elements of this queue except
1033            ///   for the front element. In other words, it is the queue obtained by
1034            ///   popping the front element.
1035            ///
1036            /// # Examples
1037            ///
1038            /// ```ignore
1039            /// use orx_meta::queue::*;
1040            ///
1041            /// let queue = Queue::new(42);
1042            /// let num = queue.pop(); // QueueSingle::pop just returns the front
1043            /// assert_eq!(num, 42);
1044            ///
1045            /// let queue = Queue::new(42).push(true).push('x').push("foo");
1046            ///
1047            /// let (num, queue) = queue.pop(); // Queue::pop returns (front, back)
1048            /// assert_eq!(num, 42);
1049            /// assert_eq!(queue, Queue::new(true).push('x').push("foo"));
1050            ///
1051            /// let (flag, queue) = queue.pop();
1052            /// assert_eq!(flag, true);
1053            /// assert_eq!(queue, Queue::new('x').push("foo"));
1054            ///
1055            /// let (c, queue) = queue.pop();
1056            /// assert_eq!(c, 'x');
1057            /// assert_eq!(queue, Queue::new("foo"));
1058            ///
1059            /// let s = queue.pop();
1060            /// assert_eq!(s, "foo");
1061            /// ```
1062            pub fn pop(self) -> (F, B) {
1063                (self.f, self.b)
1064            }
1065        }
1066
1067        impl<$($g_lt ,)* F, B, $($g ,)*> core::fmt::Debug for $pair<$($g_lt ,)* $($g ,)* F, B>
1068        where
1069            F: core::fmt::Debug,
1070            B: core::fmt::Debug,
1071            F: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1072            B: $q<$($g_lt ,)* $($g ,)*>,
1073            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
1074        {
1075            fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1076                write!(f, "{}({:?}, {:?})", stringify!($pair), self.f, self.b)
1077            }
1078        }
1079
1080        impl<$($g_lt ,)* F, B, $($g ,)*> $q<$($g_lt ,)* $($g ,)*> for $pair<$($g_lt ,)* $($g ,)* F, B>
1081        where
1082            F: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1083            B: $q<$($g_lt ,)* $($g ,)*>,
1084            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
1085        {
1086            type PushBack<Elem> = $pair<$($g_lt ,)* $($g ,)* F, B::PushBack<Elem>>
1087            where
1088                Elem: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *;
1089
1090            type Front = F;
1091
1092            type Back = B;
1093
1094            const LEN: usize = 1 + B::LEN;
1095
1096            fn push<Elem>(self, x: Elem) -> Self::PushBack<Elem>
1097            where
1098                Elem: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *
1099            {
1100                $pair::from_fb(self.f, self.b.push(x))
1101            }
1102
1103            #[inline(always)]
1104            fn front(&self) -> &Self::Front {
1105                &self.f
1106            }
1107
1108            #[inline(always)]
1109            fn front_mut(&mut self) -> &mut Self::Front {
1110                &mut self.f
1111            }
1112
1113            #[inline(always)]
1114            fn into_front(self) -> Self::Front {
1115                self.f
1116            }
1117        }
1118    };
1119}
1120
1121// # 2. builder
1122
1123#[doc(hidden)]
1124#[macro_export]
1125macro_rules! define_queue_builder {
1126    (
1127        lt => [$($g_lt:tt), *];
1128        generics => [ $( $g:tt $( : $( $g_bnd:ident $( < $( $g_bnd_g:tt ),* > )? )| * )? ), * ];
1129        queue => [$q:ident ; $empty:ident, $pair:ident];
1130        builder => $builder:ident;
1131    ) => {
1132
1133        // builder
1134
1135        /// A type-safe builder for queues such that:
1136        ///
1137        /// * `push` can only be called correct number of times with correct types,
1138        /// * `finish` can only be called when all elements to reach the `Target` type are pushed.
1139        ///
1140        /// Further, since queues can represent any struct, `QueueBuilder` can be used as a generic builder for any struct or tuple.
1141        ///
1142        /// # Example
1143        ///
1144        /// In the following example, we want to build a queue of four elements of types `u32`, `bool`, `char` and `String` respectively.
1145        ///
1146        /// For this, we can create a builder with `QueueBuilder::<MyQueue>::new()` where `MyQueue` is the target type to instantiate.
1147        ///
1148        /// ```ignore
1149        /// use orx_meta::queue::*;
1150        ///
1151        /// type MyQueue = Queue<u32, Queue<bool, Queue<char, QueueSingle<String>>>>;
1152        ///
1153        /// let instance = QueueBuilder::<MyQueue>::new()
1154        ///     .push(42)
1155        ///     .push(true)
1156        ///     .push('x')
1157        ///     .push("foo".to_string())
1158        ///     .finish();
1159        /// assert_eq!(instance.as_tuple(), (&42, &true, &'x', &"foo".to_string()));
1160        /// ```
1161        ///
1162        /// This provides a convenient way to build complex types without errors while getting compiler support on what to push next.
1163        /// However, it is not easy to hand-write the type alias for complex recursive queue types.
1164        /// Therefore, this builder pattern is most useful when used together with the [`queue_of`] macro.
1165        /// The above example could be re-written as follows with the `queue_of` macro.
1166        ///
1167        /// [`queue_of`]: crate::queue_of
1168        ///
1169        /// ```ignore
1170        /// use orx_meta::queue::*;
1171        /// use orx_meta::queue_of;
1172        ///
1173        /// type MyQueue = queue_of!(u32, bool, char, String);
1174        ///
1175        /// let instance = QueueBuilder::<MyQueue>::new()
1176        ///     .push(42)
1177        ///     .push(true)
1178        ///     .push('x')
1179        ///     .push("foo".to_string())
1180        ///     .finish();
1181        /// assert_eq!(instance.as_tuple(), (&42, &true, &'x', &"foo".to_string()));
1182        /// ```
1183        ///
1184        /// ## Examples - Type Safety
1185        ///
1186        /// Note that this builder pattern is type safe in the sense that neither of the following wrong implementations compiles.
1187        ///
1188        /// Here the elements are pushed in the wrong order:
1189        ///
1190        /// ```compile_fail ignore
1191        /// use orx_meta::queue::*;
1192        /// use orx_meta::queue_of;
1193        ///
1194        /// type MyQueue = queue_of!(u32, bool, char, String);
1195        ///
1196        /// let instance = QueueBuilder::<MyQueue>::new()
1197        ///     .push(true) // wrong order!
1198        ///     .push(42)
1199        ///     .push('x')
1200        ///     .push("foo".to_string())
1201        ///     .finish();
1202        /// assert_eq!(instance.as_tuple(), (&42, &true, &'x', &"foo".to_string()));
1203        /// ```
1204        ///
1205        /// And here, not all elements are pushed:
1206        ///
1207        /// ```compile_fail ignore
1208        /// use orx_meta::queue::*;
1209        /// use orx_meta::queue_of;
1210        ///
1211        /// type MyQueue = queue_of!(u32, bool, char, String);
1212        ///
1213        /// let instance = QueueBuilder::<MyQueue>::new()
1214        ///     .push(42)
1215        ///     .push(true)
1216        ///     .push('x')
1217        ///     .finish(); // forgot to push the String
1218        /// assert_eq!(instance.as_tuple(), (&42, &true, &'x', &"foo".to_string()));
1219        /// ```
1220        pub struct $builder<$($g_lt ,)* $($g ,)* Target>
1221        where
1222            Target:  $q<$($g_lt ,)* $($g ,)*>,
1223            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
1224        {
1225            target: core::marker::PhantomData<Target>,
1226        }
1227
1228        impl<$($g_lt ,)* $($g ,)* Target> Default for $builder<$($g_lt ,)* $($g ,)* Target>
1229        where
1230            Target:  $q<$($g_lt ,)* $($g ,)*>,
1231            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
1232        {
1233            fn default() -> Self {
1234                Self::new()
1235            }
1236        }
1237
1238        impl<$($g_lt ,)* $($g ,)* Target> $builder<$($g_lt ,)* $($g ,)* Target>
1239        where
1240            Target:  $q<$($g_lt ,)* $($g ,)*>,
1241            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
1242        {
1243            /// Creates a new empty builder for the `Target` type defined as the generic argument.
1244            pub fn new() -> Self {
1245                Self {
1246                    target: Default::default(),
1247                }
1248            }
1249
1250            /// Pushes the next `element` to build the target type.
1251            #[inline(always)]
1252            pub fn push(
1253                self,
1254                element: Target::Front,
1255            ) -> QueueBuilding<Target, Target::Back, $empty<$($g_lt ,)* $($g ,)* Target::Front>> {
1256                QueueBuilding::new($empty::new(element))
1257            }
1258        }
1259
1260        // building
1261
1262        pub struct QueueBuilding<$($g_lt ,)* $($g ,)* Target, Remaining, Current>
1263        where
1264            Target:  $q<$($g_lt ,)* $($g ,)*>,
1265            Remaining:  $q<$($g_lt ,)* $($g ,)*>,
1266            Current:  $q<$($g_lt ,)* $($g ,)*>,
1267            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
1268        {
1269            target: core::marker::PhantomData<Target>,
1270            remaining: core::marker::PhantomData<Remaining>,
1271            current: Current,
1272            phantom: core::marker::PhantomData<$(&$g_lt)* ($($g ,)*)>,
1273        }
1274
1275        impl<$($g_lt ,)* $($g ,)* Target, Remaining, Current> QueueBuilding<$($g_lt ,)* $($g ,)* Target, Remaining, Current>
1276        where
1277            Target:  $q<$($g_lt ,)* $($g ,)*>,
1278            Remaining:  $q<$($g_lt ,)* $($g ,)*>,
1279            Current:  $q<$($g_lt ,)* $($g ,)*>,
1280            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
1281        {
1282            #[inline(always)]
1283            fn new(current: Current) -> Self {
1284                Self {
1285                    target: Default::default(),
1286                    remaining: Default::default(),
1287                    current: current,
1288                    phantom: Default::default(),
1289                }
1290            }
1291
1292            /// Pushes the next `element` to build the target type.
1293            #[inline(always)]
1294            pub fn push(
1295                self,
1296                element: Remaining::Front,
1297            ) -> QueueBuilding<Target, Remaining::Back, Current::PushBack<Remaining::Front>> {
1298                QueueBuilding::new(self.current.push(element))
1299            }
1300
1301            /// Completes the builder and returns the built target type.
1302            #[inline(always)]
1303            pub fn finish(self) -> Current
1304            where
1305                Target: $q<$($g_lt ,)* $($g ,)* Front = Current::Front, Back = Current::Back>,
1306            {
1307                self.current
1308            }
1309        }
1310    };
1311}
1312
1313// # 3. tuple
1314
1315#[doc(hidden)]
1316#[macro_export]
1317macro_rules! define_nonempty_queue_tuple_transformation {
1318    (
1319        lt => [$($g_lt:tt), *];
1320        generics => [ $( $g:tt $( : $( $g_bnd:ident $( < $( $g_bnd_g:tt ),* > )? )| * )? ), * ];
1321        elements => [ $( $el_bnd:ident $( < $( $el_bnd_g:tt ),* > )? )| * ];
1322        queue => [$q:ident ; $empty:ident, $pair:ident];
1323    ) => {
1324        // tuple - 1
1325
1326        #[allow(dead_code)]
1327        impl<$($g_lt ,)* X1, $($g ,)*> $empty<$($g_lt ,)* $($g ,)* X1>
1328        where
1329            X1: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1330            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
1331        {
1332            /// Converts the queue into its flat tuple representation.
1333            ///
1334            /// # Examples
1335            ///
1336            /// ```ignore
1337            /// use orx_meta::queue::*;
1338            ///
1339            /// let queue = Queue::new(42);
1340            /// assert_eq!(queue.into_tuple(), 42);
1341            ///
1342            /// let queue = Queue::new(42).push(true);
1343            /// assert_eq!(queue.into_tuple(), (42, true));
1344            ///
1345            /// let queue = Queue::new(42).push(true).push('x').push("foo");
1346            /// assert_eq!(queue.into_tuple(), (42, true, 'x', "foo"));
1347            /// ```
1348            #[inline(always)]
1349            pub fn into_tuple(self) -> X1 {
1350                self.f
1351            }
1352
1353            /// Returns a flat tuple representation of references to elements in the queue.
1354            ///
1355            /// # Examples
1356            ///
1357            /// ```ignore
1358            /// use orx_meta::queue::*;
1359            ///
1360            /// let queue = Queue::new(42);
1361            /// assert_eq!(queue.as_tuple(), &42);
1362            ///
1363            /// let queue = Queue::new(42).push(true);
1364            /// assert_eq!(queue.as_tuple(), (&42, &true));
1365            ///
1366            /// let queue = Queue::new(42).push(true).push('x').push("foo");
1367            /// assert_eq!(queue.as_tuple(), (&42, &true, &'x', &"foo"));
1368            /// ```
1369            #[inline(always)]
1370            pub fn as_tuple(&self) -> &X1 {
1371                &self.f
1372            }
1373
1374            /// Returns a flat tuple representation of mutable references to elements in the queue.
1375            ///
1376            /// # Examples
1377            ///
1378            /// ```ignore
1379            /// use orx_meta::queue::*;
1380            ///
1381            /// let mut queue = Queue::new(42);
1382            /// let a = queue.as_tuple_mut();
1383            /// *a *= 2;
1384            /// assert_eq!(queue.as_tuple(), &84);
1385            ///
1386            /// let mut queue = Queue::new(42).push(true);
1387            /// let (a, b) = queue.as_tuple_mut();
1388            /// *a *= 2;
1389            /// *b = false;
1390            /// assert_eq!(queue.as_tuple(), (&84, &false));
1391            ///
1392            /// let mut queue = Queue::new(42).push(true).push('x').push("foo");
1393            /// let (a, b, c, d) = queue.as_tuple_mut();
1394            /// *a *= 2;
1395            /// *b = false;
1396            /// *c = 'y';
1397            /// *d = "bar";
1398            /// assert_eq!(queue.as_tuple(), (&84, &false, &'y', &"bar"));
1399            /// ```
1400            #[inline(always)]
1401            pub fn as_tuple_mut(&mut self) -> &mut X1 {
1402                &mut self.f
1403            }
1404        }
1405
1406        impl<$($g_lt ,)* $($g ,)* X1> From<X1> for $empty<$($g_lt ,)* $($g ,)* X1>
1407        where
1408            X1: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1409            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
1410        {
1411            #[inline(always)]
1412            fn from(x: X1) -> Self {
1413                $empty::new(x)
1414            }
1415        }
1416
1417        // tuple - 2
1418
1419        #[allow(dead_code)]
1420        impl<$($g_lt ,)* $($g ,)* X1, X2> $pair<$($g_lt ,)* $($g ,)* X1, $empty<$($g_lt ,)* $($g ,)* X2>>
1421        where
1422            X1: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1423            X2: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1424            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
1425        {
1426            /// Converts the queue into its flat tuple representation.
1427            ///
1428            /// # Examples
1429            ///
1430            /// ```ignore
1431            /// use orx_meta::queue::*;
1432            ///
1433            /// let queue = Queue::new(42);
1434            /// assert_eq!(queue.into_tuple(), 42);
1435            ///
1436            /// let queue = Queue::new(42).push(true);
1437            /// assert_eq!(queue.into_tuple(), (42, true));
1438            ///
1439            /// let queue = Queue::new(42).push(true).push('x').push("foo");
1440            /// assert_eq!(queue.into_tuple(), (42, true, 'x', "foo"));
1441            /// ```
1442            #[inline(always)]
1443            pub fn into_tuple(self) -> (X1, X2) {
1444                (self.f, self.b.f)
1445            }
1446
1447            /// Returns a flat tuple representation of references to elements in the queue.
1448            ///
1449            /// # Examples
1450            ///
1451            /// ```ignore
1452            /// use orx_meta::queue::*;
1453            ///
1454            /// let queue = Queue::new(42);
1455            /// assert_eq!(queue.as_tuple(), &42);
1456            ///
1457            /// let queue = Queue::new(42).push(true);
1458            /// assert_eq!(queue.as_tuple(), (&42, &true));
1459            ///
1460            /// let queue = Queue::new(42).push(true).push('x').push("foo");
1461            /// assert_eq!(queue.as_tuple(), (&42, &true, &'x', &"foo"));
1462            /// ```
1463            #[inline(always)]
1464            pub fn as_tuple(&self) -> (&X1, &X2) {
1465                (&self.f, &self.b.f)
1466            }
1467
1468            /// Returns a flat tuple representation of mutable references to elements in the queue.
1469            ///
1470            /// # Examples
1471            ///
1472            /// ```ignore
1473            /// use orx_meta::queue::*;
1474            ///
1475            /// let mut queue = Queue::new(42);
1476            /// let a = queue.as_tuple_mut();
1477            /// *a *= 2;
1478            /// assert_eq!(queue.as_tuple(), &84);
1479            ///
1480            /// let mut queue = Queue::new(42).push(true);
1481            /// let (a, b) = queue.as_tuple_mut();
1482            /// *a *= 2;
1483            /// *b = false;
1484            /// assert_eq!(queue.as_tuple(), (&84, &false));
1485            ///
1486            /// let mut queue = Queue::new(42).push(true).push('x').push("foo");
1487            /// let (a, b, c, d) = queue.as_tuple_mut();
1488            /// *a *= 2;
1489            /// *b = false;
1490            /// *c = 'y';
1491            /// *d = "bar";
1492            /// assert_eq!(queue.as_tuple(), (&84, &false, &'y', &"bar"));
1493            /// ```
1494            #[inline(always)]
1495            pub fn as_tuple_mut(&mut self) -> (&mut X1, &mut X2) {
1496                (&mut self.f, &mut self.b.f)
1497            }
1498        }
1499
1500        impl<$($g_lt ,)* $($g ,)* X1, X2> From<(X1, X2)> for $pair<$($g_lt ,)* $($g ,)* X1, $empty<$($g_lt ,)* $($g ,)* X2>>
1501        where
1502            X1: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1503            X2: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1504            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
1505        {
1506            #[inline(always)]
1507            fn from(x: (X1, X2)) -> Self {
1508                $pair::from_fb(x.0, $empty::new(x.1))
1509            }
1510        }
1511
1512        // tuple - 3
1513
1514        #[allow(dead_code)]
1515        impl<$($g_lt ,)* $($g ,)* X1, X2, X3>
1516            $pair<$($g_lt ,)* $($g ,)* X1,
1517                $pair<$($g_lt ,)* $($g ,)* X2, $empty<$($g_lt ,)* $($g ,)* X3>>
1518            >
1519        where
1520            X1: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1521            X2: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1522            X3: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1523            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
1524        {
1525            /// Converts the queue into its flat tuple representation.
1526            ///
1527            /// # Examples
1528            ///
1529            /// ```ignore
1530            /// use orx_meta::queue::*;
1531            ///
1532            /// let queue = Queue::new(42);
1533            /// assert_eq!(queue.into_tuple(), 42);
1534            ///
1535            /// let queue = Queue::new(42).push(true);
1536            /// assert_eq!(queue.into_tuple(), (42, true));
1537            ///
1538            /// let queue = Queue::new(42).push(true).push('x').push("foo");
1539            /// assert_eq!(queue.into_tuple(), (42, true, 'x', "foo"));
1540            /// ```
1541            #[inline(always)]
1542            pub fn into_tuple(self) -> (X1, X2, X3) {
1543                (self.f, self.b.f, self.b.b.f)
1544            }
1545
1546            /// Returns a flat tuple representation of references to elements in the queue.
1547            ///
1548            /// # Examples
1549            ///
1550            /// ```ignore
1551            /// use orx_meta::queue::*;
1552            ///
1553            /// let queue = Queue::new(42);
1554            /// assert_eq!(queue.as_tuple(), &42);
1555            ///
1556            /// let queue = Queue::new(42).push(true);
1557            /// assert_eq!(queue.as_tuple(), (&42, &true));
1558            ///
1559            /// let queue = Queue::new(42).push(true).push('x').push("foo");
1560            /// assert_eq!(queue.as_tuple(), (&42, &true, &'x', &"foo"));
1561            /// ```
1562            #[inline(always)]
1563            pub fn as_tuple(&self) -> (&X1, &X2, &X3) {
1564                (&self.f, &self.b.f, &self.b.b.f)
1565            }
1566
1567            /// Returns a flat tuple representation of mutable references to elements in the queue.
1568            ///
1569            /// # Examples
1570            ///
1571            /// ```ignore
1572            /// use orx_meta::queue::*;
1573            ///
1574            /// let mut queue = Queue::new(42);
1575            /// let a = queue.as_tuple_mut();
1576            /// *a *= 2;
1577            /// assert_eq!(queue.as_tuple(), &84);
1578            ///
1579            /// let mut queue = Queue::new(42).push(true);
1580            /// let (a, b) = queue.as_tuple_mut();
1581            /// *a *= 2;
1582            /// *b = false;
1583            /// assert_eq!(queue.as_tuple(), (&84, &false));
1584            ///
1585            /// let mut queue = Queue::new(42).push(true).push('x').push("foo");
1586            /// let (a, b, c, d) = queue.as_tuple_mut();
1587            /// *a *= 2;
1588            /// *b = false;
1589            /// *c = 'y';
1590            /// *d = "bar";
1591            /// assert_eq!(queue.as_tuple(), (&84, &false, &'y', &"bar"));
1592            /// ```
1593            #[inline(always)]
1594            pub fn as_tuple_mut(&mut self) -> (&mut X1, &mut X2, &mut X3) {
1595                (&mut self.f, &mut self.b.f, &mut self.b.b.f)
1596            }
1597        }
1598
1599        impl<$($g_lt ,)* $($g ,)* X1, X2, X3> From<(X1, X2, X3)> for
1600            $pair<$($g_lt ,)* $($g ,)* X1,
1601                $pair<$($g_lt ,)* $($g ,)* X2, $empty<$($g_lt ,)* $($g ,)* X3>>
1602            >
1603        where
1604            X1: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1605            X2: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1606            X3: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1607            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
1608        {
1609            #[inline(always)]
1610            fn from(x: (X1, X2, X3)) -> Self {
1611                $pair::from_fb(x.0, $pair::from_fb(x.1, $empty::new(x.2)))
1612            }
1613        }
1614
1615        // tuple - 4
1616
1617        #[allow(dead_code)]
1618        impl<$($g_lt ,)* $($g ,)* X1, X2, X3, X4>
1619            $pair<$($g_lt ,)* $($g ,)* X1,
1620                $pair<$($g_lt ,)* $($g ,)* X2,
1621                    $pair<$($g_lt ,)* $($g ,)* X3, $empty<$($g_lt ,)* $($g ,)* X4>>
1622                >
1623            >
1624        where
1625            X1: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1626            X2: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1627            X3: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1628            X4: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1629            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
1630        {
1631            /// Converts the queue into its flat tuple representation.
1632            ///
1633            /// # Examples
1634            ///
1635            /// ```ignore
1636            /// use orx_meta::queue::*;
1637            ///
1638            /// let queue = Queue::new(42);
1639            /// assert_eq!(queue.into_tuple(), 42);
1640            ///
1641            /// let queue = Queue::new(42).push(true);
1642            /// assert_eq!(queue.into_tuple(), (42, true));
1643            ///
1644            /// let queue = Queue::new(42).push(true).push('x').push("foo");
1645            /// assert_eq!(queue.into_tuple(), (42, true, 'x', "foo"));
1646            /// ```
1647            #[inline(always)]
1648            pub fn into_tuple(self) -> (X1, X2, X3, X4) {
1649                (self.f, self.b.f, self.b.b.f, self.b.b.b.f)
1650            }
1651
1652            /// Returns a flat tuple representation of references to elements in the queue.
1653            ///
1654            /// # Examples
1655            ///
1656            /// ```ignore
1657            /// use orx_meta::queue::*;
1658            ///
1659            /// let queue = Queue::new(42);
1660            /// assert_eq!(queue.as_tuple(), &42);
1661            ///
1662            /// let queue = Queue::new(42).push(true);
1663            /// assert_eq!(queue.as_tuple(), (&42, &true));
1664            ///
1665            /// let queue = Queue::new(42).push(true).push('x').push("foo");
1666            /// assert_eq!(queue.as_tuple(), (&42, &true, &'x', &"foo"));
1667            /// ```
1668            #[inline(always)]
1669            pub fn as_tuple(&self) -> (&X1, &X2, &X3, &X4) {
1670                (&self.f, &self.b.f, &self.b.b.f, &self.b.b.b.f)
1671            }
1672
1673            /// Returns a flat tuple representation of mutable references to elements in the queue.
1674            ///
1675            /// # Examples
1676            ///
1677            /// ```ignore
1678            /// use orx_meta::queue::*;
1679            ///
1680            /// let mut queue = Queue::new(42);
1681            /// let a = queue.as_tuple_mut();
1682            /// *a *= 2;
1683            /// assert_eq!(queue.as_tuple(), &84);
1684            ///
1685            /// let mut queue = Queue::new(42).push(true);
1686            /// let (a, b) = queue.as_tuple_mut();
1687            /// *a *= 2;
1688            /// *b = false;
1689            /// assert_eq!(queue.as_tuple(), (&84, &false));
1690            ///
1691            /// let mut queue = Queue::new(42).push(true).push('x').push("foo");
1692            /// let (a, b, c, d) = queue.as_tuple_mut();
1693            /// *a *= 2;
1694            /// *b = false;
1695            /// *c = 'y';
1696            /// *d = "bar";
1697            /// assert_eq!(queue.as_tuple(), (&84, &false, &'y', &"bar"));
1698            /// ```
1699            #[inline(always)]
1700            pub fn as_tuple_mut(&mut self) -> (&mut X1, &mut X2, &mut X3, &mut X4) {
1701                (&mut self.f, &mut self.b.f, &mut self.b.b.f, &mut self.b.b.b.f)
1702            }
1703        }
1704
1705        impl<$($g_lt ,)* $($g ,)* X1, X2, X3, X4> From<(X1, X2, X3, X4)> for
1706            $pair<$($g_lt ,)* $($g ,)* X1,
1707                $pair<$($g_lt ,)* $($g ,)* X2,
1708                    $pair<$($g_lt ,)* $($g ,)* X3, $empty<$($g_lt ,)* $($g ,)* X4>>
1709                >
1710            >
1711        where
1712            X1: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1713            X2: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1714            X3: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1715            X4: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1716            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
1717        {
1718            #[inline(always)]
1719            fn from(x: (X1, X2, X3, X4)) -> Self {
1720                $pair::from_fb(x.0, $pair::from_fb(x.1, $pair::from_fb(x.2, $empty::new(x.3))))
1721            }
1722        }
1723
1724        // tuple - 5
1725
1726        #[allow(dead_code)]
1727        impl<$($g_lt ,)* $($g ,)* X1, X2, X3, X4, X5>
1728            $pair<$($g_lt ,)* $($g ,)* X1,
1729                $pair<$($g_lt ,)* $($g ,)* X2,
1730                    $pair<$($g_lt ,)* $($g ,)* X3,
1731                        $pair<$($g_lt ,)* $($g ,)* X4, $empty<$($g_lt ,)* $($g ,)* X5>>
1732                    >
1733                >
1734            >
1735        where
1736            X1: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1737            X2: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1738            X3: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1739            X4: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1740            X5: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1741            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
1742        {
1743            /// Converts the queue into its flat tuple representation.
1744            ///
1745            /// # Examples
1746            ///
1747            /// ```ignore
1748            /// use orx_meta::queue::*;
1749            ///
1750            /// let queue = Queue::new(42);
1751            /// assert_eq!(queue.into_tuple(), 42);
1752            ///
1753            /// let queue = Queue::new(42).push(true);
1754            /// assert_eq!(queue.into_tuple(), (42, true));
1755            ///
1756            /// let queue = Queue::new(42).push(true).push('x').push("foo");
1757            /// assert_eq!(queue.into_tuple(), (42, true, 'x', "foo"));
1758            /// ```
1759            #[inline(always)]
1760            pub fn into_tuple(self) -> (X1, X2, X3, X4, X5) {
1761                (self.f, self.b.f, self.b.b.f, self.b.b.b.f, self.b.b.b.b.f)
1762            }
1763
1764            /// Returns a flat tuple representation of references to elements in the queue.
1765            ///
1766            /// # Examples
1767            ///
1768            /// ```ignore
1769            /// use orx_meta::queue::*;
1770            ///
1771            /// let queue = Queue::new(42);
1772            /// assert_eq!(queue.as_tuple(), &42);
1773            ///
1774            /// let queue = Queue::new(42).push(true);
1775            /// assert_eq!(queue.as_tuple(), (&42, &true));
1776            ///
1777            /// let queue = Queue::new(42).push(true).push('x').push("foo");
1778            /// assert_eq!(queue.as_tuple(), (&42, &true, &'x', &"foo"));
1779            /// ```
1780            #[inline(always)]
1781            pub fn as_tuple(&self) -> (&X1, &X2, &X3, &X4, &X5) {
1782                (&self.f, &self.b.f, &self.b.b.f, &self.b.b.b.f, &self.b.b.b.b.f)
1783            }
1784
1785            /// Returns a flat tuple representation of mutable references to elements in the queue.
1786            ///
1787            /// # Examples
1788            ///
1789            /// ```ignore
1790            /// use orx_meta::queue::*;
1791            ///
1792            /// let mut queue = Queue::new(42);
1793            /// let a = queue.as_tuple_mut();
1794            /// *a *= 2;
1795            /// assert_eq!(queue.as_tuple(), &84);
1796            ///
1797            /// let mut queue = Queue::new(42).push(true);
1798            /// let (a, b) = queue.as_tuple_mut();
1799            /// *a *= 2;
1800            /// *b = false;
1801            /// assert_eq!(queue.as_tuple(), (&84, &false));
1802            ///
1803            /// let mut queue = Queue::new(42).push(true).push('x').push("foo");
1804            /// let (a, b, c, d) = queue.as_tuple_mut();
1805            /// *a *= 2;
1806            /// *b = false;
1807            /// *c = 'y';
1808            /// *d = "bar";
1809            /// assert_eq!(queue.as_tuple(), (&84, &false, &'y', &"bar"));
1810            /// ```
1811            #[inline(always)]
1812            pub fn as_tuple_mut(&mut self) -> (&mut X1, &mut X2, &mut X3, &mut X4, &mut X5) {
1813                (&mut self.f, &mut self.b.f, &mut self.b.b.f, &mut self.b.b.b.f, &mut self.b.b.b.b.f)
1814            }
1815        }
1816
1817        impl<$($g_lt ,)* $($g ,)* X1, X2, X3, X4, X5> From<(X1, X2, X3, X4, X5)> for
1818            $pair<$($g_lt ,)* $($g ,)* X1,
1819                $pair<$($g_lt ,)* $($g ,)* X2,
1820                    $pair<$($g_lt ,)* $($g ,)* X3,
1821                        $pair<$($g_lt ,)* $($g ,)* X4, $empty<$($g_lt ,)* $($g ,)* X5>>
1822                    >
1823                >
1824            >
1825        where
1826            X1: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1827            X2: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1828            X3: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1829            X4: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1830            X5: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1831            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
1832        {
1833            #[inline(always)]
1834            fn from(x: (X1, X2, X3, X4, X5)) -> Self {
1835                $pair::from_fb(x.0, $pair::from_fb(x.1, $pair::from_fb(x.2, $pair::from_fb(x.3, $empty::new(x.4)))))
1836            }
1837        }
1838
1839        // tuple - 6
1840
1841        #[allow(dead_code)]
1842        impl<$($g_lt ,)* $($g ,)* X1, X2, X3, X4, X5, X6>
1843            $pair<$($g_lt ,)* $($g ,)* X1,
1844                $pair<$($g_lt ,)* $($g ,)* X2,
1845                    $pair<$($g_lt ,)* $($g ,)* X3,
1846                        $pair<$($g_lt ,)* $($g ,)* X4,
1847                            $pair<$($g_lt ,)* $($g ,)* X5, $empty<$($g_lt ,)* $($g ,)* X6>>
1848                        >
1849                    >
1850                >
1851            >
1852        where
1853            X1: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1854            X2: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1855            X3: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1856            X4: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1857            X5: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1858            X6: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1859            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
1860        {
1861            /// Converts the queue into its flat tuple representation.
1862            ///
1863            /// # Examples
1864            ///
1865            /// ```ignore
1866            /// use orx_meta::queue::*;
1867            ///
1868            /// let queue = Queue::new(42);
1869            /// assert_eq!(queue.into_tuple(), 42);
1870            ///
1871            /// let queue = Queue::new(42).push(true);
1872            /// assert_eq!(queue.into_tuple(), (42, true));
1873            ///
1874            /// let queue = Queue::new(42).push(true).push('x').push("foo");
1875            /// assert_eq!(queue.into_tuple(), (42, true, 'x', "foo"));
1876            /// ```
1877            #[inline(always)]
1878            pub fn into_tuple(self) -> (X1, X2, X3, X4, X5, X6) {
1879                (self.f, self.b.f, self.b.b.f, self.b.b.b.f, self.b.b.b.b.f, self.b.b.b.b.b.f)
1880            }
1881
1882            /// Returns a flat tuple representation of references to elements in the queue.
1883            ///
1884            /// # Examples
1885            ///
1886            /// ```ignore
1887            /// use orx_meta::queue::*;
1888            ///
1889            /// let queue = Queue::new(42);
1890            /// assert_eq!(queue.as_tuple(), &42);
1891            ///
1892            /// let queue = Queue::new(42).push(true);
1893            /// assert_eq!(queue.as_tuple(), (&42, &true));
1894            ///
1895            /// let queue = Queue::new(42).push(true).push('x').push("foo");
1896            /// assert_eq!(queue.as_tuple(), (&42, &true, &'x', &"foo"));
1897            /// ```
1898            #[inline(always)]
1899            pub fn as_tuple(&self) -> (&X1, &X2, &X3, &X4, &X5, &X6) {
1900                (&self.f, &self.b.f, &self.b.b.f, &self.b.b.b.f, &self.b.b.b.b.f, &self.b.b.b.b.b.f)
1901            }
1902
1903            /// Returns a flat tuple representation of mutable references to elements in the queue.
1904            ///
1905            /// # Examples
1906            ///
1907            /// ```ignore
1908            /// use orx_meta::queue::*;
1909            ///
1910            /// let mut queue = Queue::new(42);
1911            /// let a = queue.as_tuple_mut();
1912            /// *a *= 2;
1913            /// assert_eq!(queue.as_tuple(), &84);
1914            ///
1915            /// let mut queue = Queue::new(42).push(true);
1916            /// let (a, b) = queue.as_tuple_mut();
1917            /// *a *= 2;
1918            /// *b = false;
1919            /// assert_eq!(queue.as_tuple(), (&84, &false));
1920            ///
1921            /// let mut queue = Queue::new(42).push(true).push('x').push("foo");
1922            /// let (a, b, c, d) = queue.as_tuple_mut();
1923            /// *a *= 2;
1924            /// *b = false;
1925            /// *c = 'y';
1926            /// *d = "bar";
1927            /// assert_eq!(queue.as_tuple(), (&84, &false, &'y', &"bar"));
1928            /// ```
1929            #[inline(always)]
1930            pub fn as_tuple_mut(&mut self) -> (&mut X1, &mut X2, &mut X3, &mut X4, &mut X5, &mut X6) {
1931                (&mut self.f, &mut self.b.f, &mut self.b.b.f, &mut self.b.b.b.f, &mut self.b.b.b.b.f, &mut self.b.b.b.b.b.f)
1932            }
1933        }
1934
1935        impl<$($g_lt ,)* $($g ,)* X1, X2, X3, X4, X5, X6> From<(X1, X2, X3, X4, X5, X6)> for
1936            $pair<$($g_lt ,)* $($g ,)* X1,
1937                $pair<$($g_lt ,)* $($g ,)* X2,
1938                    $pair<$($g_lt ,)* $($g ,)* X3,
1939                        $pair<$($g_lt ,)* $($g ,)* X4,
1940                            $pair<$($g_lt ,)* $($g ,)* X5, $empty<$($g_lt ,)* $($g ,)* X6>>
1941                        >
1942                    >
1943                >
1944            >
1945        where
1946            X1: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1947            X2: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1948            X3: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1949            X4: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1950            X5: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1951            X6: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1952            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
1953        {
1954            #[inline(always)]
1955            fn from(x: (X1, X2, X3, X4, X5, X6)) -> Self {
1956                $pair::from_fb(x.0, $pair::from_fb(x.1, $pair::from_fb(x.2, $pair::from_fb(x.3, $pair::from_fb(x.4, $empty::new(x.5))))))
1957            }
1958        }
1959
1960        // tuple - 7
1961
1962        #[allow(dead_code)]
1963        impl<$($g_lt ,)* $($g ,)* X1, X2, X3, X4, X5, X6, X7>
1964            $pair<$($g_lt ,)* $($g ,)* X1,
1965                $pair<$($g_lt ,)* $($g ,)* X2,
1966                    $pair<$($g_lt ,)* $($g ,)* X3,
1967                        $pair<$($g_lt ,)* $($g ,)* X4,
1968                            $pair<$($g_lt ,)* $($g ,)* X5,
1969                                $pair<$($g_lt ,)* $($g ,)* X6, $empty<$($g_lt ,)* $($g ,)* X7>>
1970                            >
1971                        >
1972                    >
1973                >
1974            >
1975        where
1976            X1: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1977            X2: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1978            X3: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1979            X4: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1980            X5: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1981            X6: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1982            X7: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
1983            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
1984        {
1985            /// Converts the queue into its flat tuple representation.
1986            ///
1987            /// # Examples
1988            ///
1989            /// ```ignore
1990            /// use orx_meta::queue::*;
1991            ///
1992            /// let queue = Queue::new(42);
1993            /// assert_eq!(queue.into_tuple(), 42);
1994            ///
1995            /// let queue = Queue::new(42).push(true);
1996            /// assert_eq!(queue.into_tuple(), (42, true));
1997            ///
1998            /// let queue = Queue::new(42).push(true).push('x').push("foo");
1999            /// assert_eq!(queue.into_tuple(), (42, true, 'x', "foo"));
2000            /// ```
2001            #[inline(always)]
2002            pub fn into_tuple(self) -> (X1, X2, X3, X4, X5, X6, X7) {
2003                (self.f, self.b.f, self.b.b.f, self.b.b.b.f, self.b.b.b.b.f, self.b.b.b.b.b.f, self.b.b.b.b.b.b.f)
2004            }
2005
2006            /// Returns a flat tuple representation of references to elements in the queue.
2007            ///
2008            /// # Examples
2009            ///
2010            /// ```ignore
2011            /// use orx_meta::queue::*;
2012            ///
2013            /// let queue = Queue::new(42);
2014            /// assert_eq!(queue.as_tuple(), &42);
2015            ///
2016            /// let queue = Queue::new(42).push(true);
2017            /// assert_eq!(queue.as_tuple(), (&42, &true));
2018            ///
2019            /// let queue = Queue::new(42).push(true).push('x').push("foo");
2020            /// assert_eq!(queue.as_tuple(), (&42, &true, &'x', &"foo"));
2021            /// ```
2022            #[inline(always)]
2023            pub fn as_tuple(&self) -> (&X1, &X2, &X3, &X4, &X5, &X6, &X7) {
2024                (&self.f, &self.b.f, &self.b.b.f, &self.b.b.b.f, &self.b.b.b.b.f, &self.b.b.b.b.b.f, &self.b.b.b.b.b.b.f)
2025            }
2026
2027            /// Returns a flat tuple representation of mutable references to elements in the queue.
2028            ///
2029            /// # Examples
2030            ///
2031            /// ```ignore
2032            /// use orx_meta::queue::*;
2033            ///
2034            /// let mut queue = Queue::new(42);
2035            /// let a = queue.as_tuple_mut();
2036            /// *a *= 2;
2037            /// assert_eq!(queue.as_tuple(), &84);
2038            ///
2039            /// let mut queue = Queue::new(42).push(true);
2040            /// let (a, b) = queue.as_tuple_mut();
2041            /// *a *= 2;
2042            /// *b = false;
2043            /// assert_eq!(queue.as_tuple(), (&84, &false));
2044            ///
2045            /// let mut queue = Queue::new(42).push(true).push('x').push("foo");
2046            /// let (a, b, c, d) = queue.as_tuple_mut();
2047            /// *a *= 2;
2048            /// *b = false;
2049            /// *c = 'y';
2050            /// *d = "bar";
2051            /// assert_eq!(queue.as_tuple(), (&84, &false, &'y', &"bar"));
2052            /// ```
2053            #[inline(always)]
2054            pub fn as_tuple_mut(&mut self) -> (&mut X1, &mut X2, &mut X3, &mut X4, &mut X5, &mut X6, &mut X7) {
2055                (&mut self.f, &mut self.b.f, &mut self.b.b.f, &mut self.b.b.b.f, &mut self.b.b.b.b.f, &mut self.b.b.b.b.b.f, &mut self.b.b.b.b.b.b.f)
2056            }
2057        }
2058
2059        impl<$($g_lt ,)* $($g ,)* X1, X2, X3, X4, X5, X6, X7> From<(X1, X2, X3, X4, X5, X6, X7)> for
2060            $pair<$($g_lt ,)* $($g ,)* X1,
2061                $pair<$($g_lt ,)* $($g ,)* X2,
2062                    $pair<$($g_lt ,)* $($g ,)* X3,
2063                        $pair<$($g_lt ,)* $($g ,)* X4,
2064                            $pair<$($g_lt ,)* $($g ,)* X5,
2065                                $pair<$($g_lt ,)* $($g ,)* X6, $empty<$($g_lt ,)* $($g ,)* X7>>
2066                            >
2067                        >
2068                    >
2069                >
2070            >
2071        where
2072            X1: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
2073            X2: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
2074            X3: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
2075            X4: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
2076            X5: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
2077            X6: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
2078            X7: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
2079            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
2080        {
2081            #[inline(always)]
2082            fn from(x: (X1, X2, X3, X4, X5, X6, X7)) -> Self {
2083                $pair::from_fb(x.0, $pair::from_fb(x.1, $pair::from_fb(x.2, $pair::from_fb(x.3, $pair::from_fb(x.4, $pair::from_fb(x.5, $empty::new(x.6)))))))
2084            }
2085        }
2086
2087        // tuple - 8
2088
2089        #[allow(dead_code)]
2090        impl<$($g_lt ,)* $($g ,)* X1, X2, X3, X4, X5, X6, X7, X8>
2091            $pair<$($g_lt ,)* $($g ,)* X1,
2092                $pair<$($g_lt ,)* $($g ,)* X2,
2093                    $pair<$($g_lt ,)* $($g ,)* X3,
2094                        $pair<$($g_lt ,)* $($g ,)* X4,
2095                            $pair<$($g_lt ,)* $($g ,)* X5,
2096                                $pair<$($g_lt ,)* $($g ,)* X6,
2097                                    $pair<$($g_lt ,)* $($g ,)* X7, $empty<$($g_lt ,)* $($g ,)* X8>>
2098                                >
2099                            >
2100                        >
2101                    >
2102                >
2103            >
2104        where
2105            X1: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
2106            X2: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
2107            X3: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
2108            X4: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
2109            X5: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
2110            X6: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
2111            X7: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
2112            X8: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
2113            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
2114        {
2115            /// Converts the queue into its flat tuple representation.
2116            ///
2117            /// # Examples
2118            ///
2119            /// ```ignore
2120            /// use orx_meta::queue::*;
2121            ///
2122            /// let queue = Queue::new(42);
2123            /// assert_eq!(queue.into_tuple(), 42);
2124            ///
2125            /// let queue = Queue::new(42).push(true);
2126            /// assert_eq!(queue.into_tuple(), (42, true));
2127            ///
2128            /// let queue = Queue::new(42).push(true).push('x').push("foo");
2129            /// assert_eq!(queue.into_tuple(), (42, true, 'x', "foo"));
2130            /// ```
2131            #[inline(always)]
2132            pub fn into_tuple(self) -> (X1, X2, X3, X4, X5, X6, X7, X8) {
2133                (self.f, self.b.f, self.b.b.f, self.b.b.b.f, self.b.b.b.b.f, self.b.b.b.b.b.f, self.b.b.b.b.b.b.f, self.b.b.b.b.b.b.b.f)
2134            }
2135
2136            /// Returns a flat tuple representation of references to elements in the queue.
2137            ///
2138            /// # Examples
2139            ///
2140            /// ```ignore
2141            /// use orx_meta::queue::*;
2142            ///
2143            /// let queue = Queue::new(42);
2144            /// assert_eq!(queue.as_tuple(), &42);
2145            ///
2146            /// let queue = Queue::new(42).push(true);
2147            /// assert_eq!(queue.as_tuple(), (&42, &true));
2148            ///
2149            /// let queue = Queue::new(42).push(true).push('x').push("foo");
2150            /// assert_eq!(queue.as_tuple(), (&42, &true, &'x', &"foo"));
2151            /// ```
2152            #[inline(always)]
2153            pub fn as_tuple(&self) -> (&X1, &X2, &X3, &X4, &X5, &X6, &X7, &X8) {
2154                (&self.f, &self.b.f, &self.b.b.f, &self.b.b.b.f, &self.b.b.b.b.f, &self.b.b.b.b.b.f, &self.b.b.b.b.b.b.f, &self.b.b.b.b.b.b.b.f)
2155            }
2156
2157            /// Returns a flat tuple representation of mutable references to elements in the queue.
2158            ///
2159            /// # Examples
2160            ///
2161            /// ```ignore
2162            /// use orx_meta::queue::*;
2163            ///
2164            /// let mut queue = Queue::new(42);
2165            /// let a = queue.as_tuple_mut();
2166            /// *a *= 2;
2167            /// assert_eq!(queue.as_tuple(), &84);
2168            ///
2169            /// let mut queue = Queue::new(42).push(true);
2170            /// let (a, b) = queue.as_tuple_mut();
2171            /// *a *= 2;
2172            /// *b = false;
2173            /// assert_eq!(queue.as_tuple(), (&84, &false));
2174            ///
2175            /// let mut queue = Queue::new(42).push(true).push('x').push("foo");
2176            /// let (a, b, c, d) = queue.as_tuple_mut();
2177            /// *a *= 2;
2178            /// *b = false;
2179            /// *c = 'y';
2180            /// *d = "bar";
2181            /// assert_eq!(queue.as_tuple(), (&84, &false, &'y', &"bar"));
2182            /// ```
2183            #[inline(always)]
2184            pub fn as_tuple_mut(&mut self) -> (&mut X1, &mut X2, &mut X3, &mut X4, &mut X5, &mut X6, &mut X7, &mut X8) {
2185                (&mut self.f, &mut self.b.f, &mut self.b.b.f, &mut self.b.b.b.f, &mut self.b.b.b.b.f, &mut self.b.b.b.b.b.f, &mut self.b.b.b.b.b.b.f, &mut self.b.b.b.b.b.b.b.f)
2186            }
2187        }
2188
2189        impl<$($g_lt ,)* $($g ,)* X1, X2, X3, X4, X5, X6, X7, X8> From<(X1, X2, X3, X4, X5, X6, X7, X8)> for
2190            $pair<$($g_lt ,)* $($g ,)* X1,
2191                $pair<$($g_lt ,)* $($g ,)* X2,
2192                    $pair<$($g_lt ,)* $($g ,)* X3,
2193                        $pair<$($g_lt ,)* $($g ,)* X4,
2194                            $pair<$($g_lt ,)* $($g ,)* X5,
2195                                $pair<$($g_lt ,)* $($g ,)* X6,
2196                                    $pair<$($g_lt ,)* $($g ,)* X7, $empty<$($g_lt ,)* $($g ,)* X8>>
2197                                >
2198                            >
2199                        >
2200                    >
2201                >
2202            >
2203        where
2204            X1: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
2205            X2: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
2206            X3: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
2207            X4: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
2208            X5: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
2209            X6: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
2210            X7: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
2211            X8: $( $el_bnd $( < $( $el_bnd_g ),* > )? + ) *,
2212            $( $g: $( $( $g_bnd $( < $( $g_bnd_g ),* > )? + )* )? ), *
2213        {
2214            #[inline(always)]
2215            fn from(x: (X1, X2, X3, X4, X5, X6, X7, X8)) -> Self {
2216                $pair::from_fb(x.0, $pair::from_fb(x.1, $pair::from_fb(x.2, $pair::from_fb(x.3, $pair::from_fb(x.4, $pair::from_fb(x.5, $pair::from_fb(x.6, $empty::new(x.7))))))))
2217            }
2218        }
2219    };
2220}
2221
2222// # 4. queue-of
2223
2224#[doc(hidden)]
2225#[macro_export]
2226macro_rules! define_queue_of {
2227    (
2228        lt => [$($g_lt:tt), *];
2229        generics => [ $( $g:tt $( : $( $g_bnd:ident $( < $( $g_bnd_g:tt ),* > )? )| * )? ), * ];
2230        queue => [$q:ident ; $empty:ident, $pair:ident];
2231        queue_of => $queue_of:ident;
2232    ) => {
2233        /// Recall that there exist two statically-typed queue (`StQueue`) implementations:
2234        ///
2235        /// * `QueueSingle` which includes exactly one element, and
2236        /// * `Queue` containing multiple (>=2) elements.
2237        ///
2238        /// Queues of all lengths can be represented by these two types:
2239        /// * `QueueSingle<T1>` is a queue with one element,
2240        /// * `Queue<T1, QueueSingle<T2>>` with two elements,
2241        /// * `Queue<T1, Queue<T2, QueueSingle<T3>>>` with three elements,
2242        /// * `Queue<T1, Queue<T2, Queue<T3, QueueSingle<T4>>>>` with four elements,
2243        /// * and so on, so forth.
2244        ///
2245        /// This is possible thanks to generic associated types and recursive type definition of the `Queue`.
2246        ///
2247        /// On the other hand, it might make it difficult to hand-write queue types.
2248        ///
2249        /// `queue_of` macro is a helper macro to make such type aliasing convenient whenever needed.
2250        ///
2251        /// # Examples
2252        ///
2253        /// ```ignore
2254        /// use orx_meta::queue::*;
2255        /// use orx_meta::queue_of;
2256        ///
2257        /// // written with recursive type definition
2258        /// type Q1 = Queue<i32, Queue<bool, Queue<char, QueueSingle<String>>>>;
2259        ///
2260        /// let instance: Q1 = Queue::new(42).push(true).push('x').push("foo".to_string());
2261        /// assert_eq!(instance.as_tuple(), (&42, &true, &'x', &"foo".to_string()));
2262        ///
2263        /// // alternatively, using with queue_of macro as a flat list
2264        /// type Q2 = queue_of!(i32, bool, char, String);
2265        ///
2266        /// // notice that Q1 and Q2 are aliases for the same type
2267        /// let instance2: Q2 = instance;
2268        /// ```
2269        macro_rules! $queue_of {
2270            ($t1:ty) => {
2271                $empty<$($g_lt ,)* $($g ,)* $t1>
2272            };
2273
2274            ($t1:ty, $t2:ty) => {
2275                $pair<$($g_lt ,)* $($g ,)* $t1, $empty<$($g_lt ,)* $($g ,)* $t2>>
2276            };
2277
2278            ($t1:ty, $t2:ty, $t3:ty) => {
2279                $pair<$($g_lt ,)* $($g ,)* $t1,
2280                    $pair<$($g_lt ,)* $($g ,)* $t2, $empty<$($g_lt ,)* $($g ,)* $t3>>
2281                >
2282            };
2283
2284            ($t1:ty, $t2:ty, $t3:ty, $t4:ty) => {
2285                $pair<$($g_lt ,)* $($g ,)* $t1,
2286                    $pair<$($g_lt ,)* $($g ,)* $t2,
2287                        $pair<$($g_lt ,)* $($g ,)* $t3, $empty<$($g_lt ,)* $($g ,)* $t4>>
2288                    >
2289                >
2290            };
2291
2292            ($t1:ty, $t2:ty, $t3:ty, $t4:ty, $t5:ty) => {
2293                $pair<$($g_lt ,)* $($g ,)* $t1,
2294                    $pair<$($g_lt ,)* $($g ,)* $t2,
2295                        $pair<$($g_lt ,)* $($g ,)* $t3,
2296                            $pair<$($g_lt ,)* $($g ,)* $t4, $empty<$($g_lt ,)* $($g ,)* $t5>>
2297                        >
2298                    >
2299                >
2300            };
2301
2302            ($t1:ty, $t2:ty, $t3:ty, $t4:ty, $t5:ty, $t6:ty) => {
2303                $pair<$($g_lt ,)* $($g ,)* $t1,
2304                    $pair<$($g_lt ,)* $($g ,)* $t2,
2305                        $pair<$($g_lt ,)* $($g ,)* $t3,
2306                            $pair<$($g_lt ,)* $($g ,)* $t4,
2307                                $pair<$($g_lt ,)* $($g ,)* $t5, $empty<$($g_lt ,)* $($g ,)* $t6>>
2308                            >
2309                        >
2310                    >
2311                >
2312            };
2313
2314            ($t1:ty, $t2:ty, $t3:ty, $t4:ty, $t5:ty, $t6:ty, $t7:ty) => {
2315                $pair<$($g_lt ,)* $($g ,)* $t1,
2316                    $pair<$($g_lt ,)* $($g ,)* $t2,
2317                        $pair<$($g_lt ,)* $($g ,)* $t3,
2318                            $pair<$($g_lt ,)* $($g ,)* $t4,
2319                                $pair<$($g_lt ,)* $($g ,)* $t5,
2320                                    $pair<$($g_lt ,)* $($g ,)* $t6, $empty<$($g_lt ,)* $($g ,)* $t7>>
2321                                >
2322                            >
2323                        >
2324                    >
2325                >
2326            };
2327
2328            ($t1:ty, $t2:ty, $t3:ty, $t4:ty, $t5:ty, $t6:ty, $t7:ty, $t8:ty) => {
2329                $pair<$($g_lt ,)* $($g ,)* $t1,
2330                    $pair<$($g_lt ,)* $($g ,)* $t2,
2331                        $pair<$($g_lt ,)* $($g ,)* $t3,
2332                            $pair<$($g_lt ,)* $($g ,)* $t4,
2333                                $pair<$($g_lt ,)* $($g ,)* $t5,
2334                                    $pair<$($g_lt ,)* $($g ,)* $t6,
2335                                        $pair<$($g_lt ,)* $($g ,)* $t7, $empty<$($g_lt ,)* $($g ,)* $t8>>
2336                                    >
2337                                >
2338                            >
2339                        >
2340                    >
2341                >
2342            };
2343
2344            ($t1:ty, $t2:ty, $t3:ty, $t4:ty, $t5:ty, $t6:ty, $t7:ty, $t8:ty, $t9:ty) => {
2345                $pair<$($g_lt ,)* $($g ,)* $t1,
2346                    $pair<$($g_lt ,)* $($g ,)* $t2,
2347                        $pair<$($g_lt ,)* $($g ,)* $t3,
2348                            $pair<$($g_lt ,)* $($g ,)* $t4,
2349                                $pair<$($g_lt ,)* $($g ,)* $t5,
2350                                    $pair<$($g_lt ,)* $($g ,)* $t6,
2351                                        $pair<$($g_lt ,)* $($g ,)* $t7,
2352                                            $pair<$($g_lt ,)* $($g ,)* $t8, $empty<$($g_lt ,)* $($g ,)* $t9>>
2353                                        >
2354                                    >
2355                                >
2356                            >
2357                        >
2358                    >
2359                >
2360            };
2361
2362            ($t1:ty, $t2:ty, $t3:ty, $t4:ty, $t5:ty, $t6:ty, $t7:ty, $t8:ty, $t9:ty, $t10:ty) => {
2363                $pair<$($g_lt ,)* $($g ,)* $t1,
2364                    $pair<$($g_lt ,)* $($g ,)* $t2,
2365                        $pair<$($g_lt ,)* $($g ,)* $t3,
2366                            $pair<$($g_lt ,)* $($g ,)* $t4,
2367                                $pair<$($g_lt ,)* $($g ,)* $t5,
2368                                    $pair<$($g_lt ,)* $($g ,)* $t6,
2369                                        $pair<$($g_lt ,)* $($g ,)* $t7,
2370                                            $pair<$($g_lt ,)* $($g ,)* $t8,
2371                                                $pair<$($g_lt ,)* $($g ,)* $t9, $empty<$($g_lt ,)* $($g ,)* $t10>>
2372                                            >
2373                                        >
2374                                    >
2375                                >
2376                            >
2377                        >
2378                    >
2379                >
2380            };
2381
2382            ($t1:ty, $t2:ty, $t3:ty, $t4:ty, $t5:ty, $t6:ty, $t7:ty, $t8:ty, $t9:ty, $t10:ty, $t11:ty) => {
2383                $pair<$($g_lt ,)* $($g ,)* $t1,
2384                    $pair<$($g_lt ,)* $($g ,)* $t2,
2385                        $pair<$($g_lt ,)* $($g ,)* $t3,
2386                            $pair<$($g_lt ,)* $($g ,)* $t4,
2387                                $pair<$($g_lt ,)* $($g ,)* $t5,
2388                                    $pair<$($g_lt ,)* $($g ,)* $t6,
2389                                        $pair<$($g_lt ,)* $($g ,)* $t7,
2390                                            $pair<$($g_lt ,)* $($g ,)* $t8,
2391                                                $pair<$($g_lt ,)* $($g ,)* $t9,
2392                                                    $pair<$($g_lt ,)* $($g ,)* $t10, $empty<$($g_lt ,)* $($g ,)* $t11>>
2393                                                >
2394                                            >
2395                                        >
2396                                    >
2397                                >
2398                            >
2399                        >
2400                    >
2401                >
2402            };
2403
2404            ($t1:ty, $t2:ty, $t3:ty, $t4:ty, $t5:ty, $t6:ty, $t7:ty, $t8:ty, $t9:ty, $t10:ty, $t11:ty, $t12:ty) => {
2405                $pair<$($g_lt ,)* $($g ,)* $t1,
2406                    $pair<$($g_lt ,)* $($g ,)* $t2,
2407                        $pair<$($g_lt ,)* $($g ,)* $t3,
2408                            $pair<$($g_lt ,)* $($g ,)* $t4,
2409                                $pair<$($g_lt ,)* $($g ,)* $t5,
2410                                    $pair<$($g_lt ,)* $($g ,)* $t6,
2411                                        $pair<$($g_lt ,)* $($g ,)* $t7,
2412                                            $pair<$($g_lt ,)* $($g ,)* $t8,
2413                                                $pair<$($g_lt ,)* $($g ,)* $t9,
2414                                                    $pair<$($g_lt ,)* $($g ,)* $t10,
2415                                                        $pair<$($g_lt ,)* $($g ,)* $t11, $empty<$($g_lt ,)* $($g ,)* $t12>>
2416                                                    >
2417                                                >
2418                                            >
2419                                        >
2420                                    >
2421                                >
2422                            >
2423                        >
2424                    >
2425                >
2426            };
2427
2428            ($t1:ty, $t2:ty, $t3:ty, $t4:ty, $t5:ty, $t6:ty, $t7:ty, $t8:ty, $t9:ty, $t10:ty, $t11:ty, $t12:ty, $t13:ty) => {
2429                $pair<$($g_lt ,)* $($g ,)* $t1,
2430                    $pair<$($g_lt ,)* $($g ,)* $t2,
2431                        $pair<$($g_lt ,)* $($g ,)* $t3,
2432                            $pair<$($g_lt ,)* $($g ,)* $t4,
2433                                $pair<$($g_lt ,)* $($g ,)* $t5,
2434                                    $pair<$($g_lt ,)* $($g ,)* $t6,
2435                                        $pair<$($g_lt ,)* $($g ,)* $t7,
2436                                            $pair<$($g_lt ,)* $($g ,)* $t8,
2437                                                $pair<$($g_lt ,)* $($g ,)* $t9,
2438                                                    $pair<$($g_lt ,)* $($g ,)* $t10,
2439                                                        $pair<$($g_lt ,)* $($g ,)* $t11,
2440                                                            $pair<$($g_lt ,)* $($g ,)* $t12, $empty<$($g_lt ,)* $($g ,)* $t13>>
2441                                                        >
2442                                                    >
2443                                                >
2444                                            >
2445                                        >
2446                                    >
2447                                >
2448                            >
2449                        >
2450                    >
2451                >
2452            };
2453
2454            ($t1:ty, $t2:ty, $t3:ty, $t4:ty, $t5:ty, $t6:ty, $t7:ty, $t8:ty, $t9:ty, $t10:ty, $t11:ty, $t12:ty, $t13:ty, $t14:ty) => {
2455                $pair<$($g_lt ,)* $($g ,)* $t1,
2456                    $pair<$($g_lt ,)* $($g ,)* $t2,
2457                        $pair<$($g_lt ,)* $($g ,)* $t3,
2458                            $pair<$($g_lt ,)* $($g ,)* $t4,
2459                                $pair<$($g_lt ,)* $($g ,)* $t5,
2460                                    $pair<$($g_lt ,)* $($g ,)* $t6,
2461                                        $pair<$($g_lt ,)* $($g ,)* $t7,
2462                                            $pair<$($g_lt ,)* $($g ,)* $t8,
2463                                                $pair<$($g_lt ,)* $($g ,)* $t9,
2464                                                    $pair<$($g_lt ,)* $($g ,)* $t10,
2465                                                        $pair<$($g_lt ,)* $($g ,)* $t11,
2466                                                            $pair<$($g_lt ,)* $($g ,)* $t12,
2467                                                                $pair<$($g_lt ,)* $($g ,)* $t13, $empty<$($g_lt ,)* $($g ,)* $t14>>
2468                                                            >
2469                                                        >
2470                                                    >
2471                                                >
2472                                            >
2473                                        >
2474                                    >
2475                                >
2476                            >
2477                        >
2478                    >
2479                >
2480            };
2481
2482            ($t1:ty, $t2:ty, $t3:ty, $t4:ty, $t5:ty, $t6:ty, $t7:ty, $t8:ty, $t9:ty, $t10:ty, $t11:ty, $t12:ty, $t13:ty, $t14:ty, $t15:ty) => {
2483                $pair<$($g_lt ,)* $($g ,)* $t1,
2484                    $pair<$($g_lt ,)* $($g ,)* $t2,
2485                        $pair<$($g_lt ,)* $($g ,)* $t3,
2486                            $pair<$($g_lt ,)* $($g ,)* $t4,
2487                                $pair<$($g_lt ,)* $($g ,)* $t5,
2488                                    $pair<$($g_lt ,)* $($g ,)* $t6,
2489                                        $pair<$($g_lt ,)* $($g ,)* $t7,
2490                                            $pair<$($g_lt ,)* $($g ,)* $t8,
2491                                                $pair<$($g_lt ,)* $($g ,)* $t9,
2492                                                    $pair<$($g_lt ,)* $($g ,)* $t10,
2493                                                        $pair<$($g_lt ,)* $($g ,)* $t11,
2494                                                            $pair<$($g_lt ,)* $($g ,)* $t12,
2495                                                                $pair<$($g_lt ,)* $($g ,)* $t13,
2496                                                                    $pair<$($g_lt ,)* $($g ,)* $t14, $empty<$($g_lt ,)* $($g ,)* $t15>>
2497                                                                >
2498                                                            >
2499                                                        >
2500                                                    >
2501                                                >
2502                                            >
2503                                        >
2504                                    >
2505                                >
2506                            >
2507                        >
2508                    >
2509                >
2510            };
2511
2512            ($t1:ty, $t2:ty, $t3:ty, $t4:ty, $t5:ty, $t6:ty, $t7:ty, $t8:ty, $t9:ty, $t10:ty, $t11:ty, $t12:ty, $t13:ty, $t14:ty, $t15:ty, $t16:ty) => {
2513                $pair<$($g_lt ,)* $($g ,)* $t1,
2514                    $pair<$($g_lt ,)* $($g ,)* $t2,
2515                        $pair<$($g_lt ,)* $($g ,)* $t3,
2516                            $pair<$($g_lt ,)* $($g ,)* $t4,
2517                                $pair<$($g_lt ,)* $($g ,)* $t5,
2518                                    $pair<$($g_lt ,)* $($g ,)* $t6,
2519                                        $pair<$($g_lt ,)* $($g ,)* $t7,
2520                                            $pair<$($g_lt ,)* $($g ,)* $t8,
2521                                                $pair<$($g_lt ,)* $($g ,)* $t9,
2522                                                    $pair<$($g_lt ,)* $($g ,)* $t10,
2523                                                        $pair<$($g_lt ,)* $($g ,)* $t11,
2524                                                            $pair<$($g_lt ,)* $($g ,)* $t12,
2525                                                                $pair<$($g_lt ,)* $($g ,)* $t13,
2526                                                                    $pair<$($g_lt ,)* $($g ,)* $t14,
2527                                                                        $pair<$($g_lt ,)* $($g ,)* $t15, $empty<$($g_lt ,)* $($g ,)* $t16>>
2528                                                                    >
2529                                                                >
2530                                                            >
2531                                                        >
2532                                                    >
2533                                                >
2534                                            >
2535                                        >
2536                                    >
2537                                >
2538                            >
2539                        >
2540                    >
2541                >
2542            };
2543        }
2544    };
2545}