Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions library/core/src/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ use crate::cmp::Ordering::{self, *};
use crate::marker::{ConstParamTy_, StructuralPartialEq};
use crate::ops::ControlFlow::{self, Break, Continue};

macro_rules! token {
(T $t:tt) => {
T
};
(U $t:tt) => {
U
};
}

// Recursive macro for implementing n-ary tuple functions and operations
//
// Also provides implementations for tuples with lesser arity. For example, tuple_impls!(A B C)
Expand Down Expand Up @@ -37,6 +46,24 @@ macro_rules! tuple_impls {
}
}

maybe_tuple_doc! {
$($T)+ @
#[unstable(feature = "tuple_map", issue = "none")]
impl<T> ($(token!(T $T),)+) {
/// Maps a homogenous tuple as if it were an array.
#[rustc_const_unstable(feature = "tuple_map", issue = "none")]
#[allow(nonstandard_style)]
pub const fn map<F, U>(self, mut f: F) -> ($(token!(U $T),)+)
where
F: [const] FnMut(T) -> U + [const] crate::marker::Destruct
{
let ($($T,)+) = self;

($(f($T),)+)
}
}
}

maybe_tuple_doc! {
$($T)+ @
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
Loading