xtd 0.2.0
Loading...
Searching...
No Matches
xtd::linq::enumerable Class Reference
Inheritance diagram for xtd::linq::enumerable:
xtd::static_object

Definition

Provides a set of static methods for querying objects that implement ienumerable <type_t>.

Definition
template<typename type_t>
Provides a set of static methods for querying objects that implement ienumerable <type_t>.
Definition enumerable.hpp:29
Represent a static object. A static class can't be instantiated (constructors are deleted).
Definition static.hpp:20
Header
#include <xtd/linq/enumerable
Namespace
xtd::linq
Library
xtd.core

Public Static Methods

template<typename source_t >
static source_t aggregate (const xtd::collections::generic::ienumerable< source_t > &source, const xtd::func< source_t, const source_t &, const source_t & > &func)
 Applies an accumulator function over a sequence.
 
template<typename source_t , typename func_t >
static source_t aggregate (const xtd::collections::generic::ienumerable< source_t > &source, const func_t &func)
 Applies an accumulator function over a sequence.
 
template<typename source_t , typename accumulate_t >
static accumulate_t aggregate (const xtd::collections::generic::ienumerable< source_t > &source, const accumulate_t &seed, const xtd::func< accumulate_t, const source_t &, const accumulate_t & > &func)
 Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value.
 
template<typename source_t , typename accumulate_t , typename func_t >
static accumulate_t aggregate (const xtd::collections::generic::ienumerable< source_t > &source, const accumulate_t &seed, const func_t &func)
 Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value.
 
template<typename source_t , typename accumulate_t , typename result_t >
static result_t aggregate (const xtd::collections::generic::ienumerable< source_t > &source, const accumulate_t &seed, const xtd::func< accumulate_t, const source_t &, const accumulate_t & > &func, const xtd::func< result_t, const accumulate_t & > &result_selector)
 Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.
 
template<typename source_t , typename accumulate_t , typename result_t , typename func_t , typename result_selector_t >
static result_t aggregate (const xtd::collections::generic::ienumerable< source_t > &source, const accumulate_t &seed, const func_t &func, const result_selector_t &result_selector)
 Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.
 
template<typename source_t , typename accumulate_t , typename func_t , typename result_selector_t >
static accumulate_t aggregate (const xtd::collections::generic::ienumerable< source_t > &source, const accumulate_t &seed, const func_t &func, const result_selector_t &result_selector)
 Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.
 
template<typename accumulate_t , typename input_iterator_t >
static accumulate_t aggregate (input_iterator_t first, input_iterator_t last, const xtd::func< accumulate_t, const accumulate_t &, const accumulate_t & > &func)
 Applies an accumulator function over a sequence.
 
template<typename accumulate_t , typename input_iterator_t , typename func_t >
static accumulate_t aggregate (input_iterator_t first, input_iterator_t last, const func_t &func)
 Applies an accumulator function over a sequence.
 
template<typename accumulate_t , typename input_iterator_t >
static accumulate_t aggregate (input_iterator_t first, input_iterator_t last, const accumulate_t &seed, const xtd::func< accumulate_t, const accumulate_t &, const accumulate_t & > &func)
 Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value.
 
template<typename accumulate_t , typename input_iterator_t , typename func_t >
static accumulate_t aggregate (input_iterator_t first, input_iterator_t last, const accumulate_t &seed, const func_t &func)
 Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value.
 
template<typename accumulate_t , typename result_t , typename input_iterator_t >
static result_t aggregate (input_iterator_t first, input_iterator_t last, const accumulate_t &seed, const xtd::func< accumulate_t, const accumulate_t &, const accumulate_t & > &func, const xtd::func< result_t, const accumulate_t & > &result_selector)
 Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.
 
template<typename accumulate_t , typename result_t , typename input_iterator_t , typename func_t , typename result_selector_t >
static result_t aggregate (input_iterator_t first, input_iterator_t last, const accumulate_t &seed, const func_t &func, const result_selector_t &result_selector)
 Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.
 
template<typename accumulate_t , typename input_iterator_t , typename func_t , typename result_selector_t >
static accumulate_t aggregate (input_iterator_t first, input_iterator_t last, const accumulate_t &seed, const func_t &func, const result_selector_t &result_selector)
 Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.
 
template<typename source_t >
static bool all (const xtd::collections::generic::ienumerable< source_t > &source, const xtd::predicate< const source_t & > &predicate)
 Determines whether all elements of a sequence satisfy a condition.
 
template<typename source_t , typename predicate_t >
static bool all (const xtd::collections::generic::ienumerable< source_t > &source, const predicate_t &predicate)
 Determines whether all elements of a sequence satisfy a condition.
 
template<typename source_t , typename input_iterator_t >
static bool all (input_iterator_t first, input_iterator_t last, const xtd::predicate< const source_t & > &predicate)
 Determines whether all elements of a sequence satisfy a condition.
 
template<typename source_t , typename input_iterator_t , typename predicate_t >
static bool all (input_iterator_t first, input_iterator_t last, const predicate_t &predicate)
 Determines whether all elements of a sequence satisfy a condition.
 
template<typename source_t >
static bool any (const xtd::collections::generic::ienumerable< source_t > &source)
 Determines whether a sequence contains any elements.
 
template<typename source_t >
static bool any (const xtd::collections::generic::ienumerable< source_t > &source, const xtd::predicate< const source_t & > &predicate)
 Determines whether any element of a sequence satisfies a condition.
 
template<typename source_t , typename predicate_t >
static bool any (const xtd::collections::generic::ienumerable< source_t > &source, const predicate_t &predicate)
 Determines whether any elements of a sequence satisfy a condition.
 
template<typename source_t , typename input_iterator_t >
static bool any (input_iterator_t first, input_iterator_t last)
 Determines whether a sequence contains any elements.
 
template<typename source_t , typename input_iterator_t >
static bool any (input_iterator_t first, input_iterator_t last, const xtd::predicate< const source_t & > &predicate)
 Determines whether any elements of a sequence satisfy a condition.
 
template<typename source_t , typename input_iterator_t , typename predicate_t >
static bool any (input_iterator_t first, input_iterator_t last, const predicate_t &predicate)
 Determines whether any elements of a sequence satisfy a condition.
 

Member Function Documentation

◆ aggregate() [1/14]

template<typename source_t >
static source_t xtd::linq::enumerable::aggregate ( const xtd::collections::generic::ienumerable< source_t > &  source,
const xtd::func< source_t, const source_t &, const source_t & > &  func 
)
inlinestatic

Applies an accumulator function over a sequence.

Parameters
sourceAn xtd::collections::generic::ienumerable <type_t> to aggregate over.
funcAn accumulator function to be invoked on each element.
Returns
The final accumulator value.
Examples
The following code example demonstrates how to reverse the order of words in a string by using enumerable::aggregate.
#include <xtd/linq/enumerable>
#include <xtd/console>
using namespace xtd;
using namespace xtd::linq;
auto main() -> int {
auto sentence = "the quick brown fox jumps over the lazy dog"_s;
// Split the string into individual words.
auto words = sentence.split(' ');
// Prepend each word to the beginning of the new sentence to reverse the word order.
auto reversed = enumerable::aggregate(words, [](const string& working_sentence, const string& next) {
return next + " " + working_sentence;
});
console::write_line(reversed.quoted());
}
// This code produces the following output :
//
// "dog lazy the over jumps fox brown quick the"
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
static source_t aggregate(const xtd::collections::generic::ienumerable< source_t > &source, const xtd::func< source_t, const source_t &, const source_t & > &func)
Applies an accumulator function over a sequence.
Definition enumerable.hpp:42
Provides classes and interfaces that support queries that use Language-Integrated Query (LINQ).
Definition enumerable.hpp:13
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10

◆ aggregate() [2/14]

template<typename source_t , typename func_t >
static source_t xtd::linq::enumerable::aggregate ( const xtd::collections::generic::ienumerable< source_t > &  source,
const func_t &  func 
)
inlinestatic

Applies an accumulator function over a sequence.

Parameters
sourceAn xtd::collections::generic::ienumerable <type_t> to aggregate over.
funcAn accumulator function to be invoked on each element.
Returns
The final accumulator value.
Examples
The following code example demonstrates how to reverse the order of words in a string by using xtd::linq::enumerable::aggregate.
#include <xtd/linq/enumerable>
#include <xtd/console>
using namespace xtd;
using namespace xtd::linq;
auto main() -> int {
auto sentence = "the quick brown fox jumps over the lazy dog"_s;
// Split the string into individual words.
auto words = sentence.split(' ');
// Prepend each word to the beginning of the new sentence to reverse the word order.
auto reversed = enumerable::aggregate(words, [](const string& working_sentence, const string& next) {
return next + " " + working_sentence;
});
console::write_line(reversed.quoted());
}
// This code produces the following output :
//
// "dog lazy the over jumps fox brown quick the"

◆ aggregate() [3/14]

template<typename source_t , typename accumulate_t >
static accumulate_t xtd::linq::enumerable::aggregate ( const xtd::collections::generic::ienumerable< source_t > &  source,
const accumulate_t &  seed,
const xtd::func< accumulate_t, const source_t &, const accumulate_t & > &  func 
)
inlinestatic

Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value.

Parameters
sourceAn xtd::collections::generic::ienumerable <type_t> to aggregate over.
seedThe initial accumulator value.
funcAn accumulator function to be invoked on each element.
Returns
The final accumulator value.
Examples
The following code example demonstrates how to use xtd::linq::enumerable::aggregate to apply an accumulator function and use a seed value.
#include <xtd/linq/enumerable>
#include <xtd/array>
#include <xtd/console>
using namespace xtd;
using namespace xtd::linq;
auto main() -> int {
auto ints = array {4, 8, 8, 3, 9, 0, 7, 8, 2};
// Count the even numbers in the array, using a seed value of 0.
auto num_even = enumerable::aggregate(ints, 0, [](int total, int next) {
return next % 2 == 0 ? total + 1 : total;
});
console::write_line("The number of even integers is: {}", num_even);
}
// This code produces the following output :
//
// The number of even integers is: 6
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:58

◆ aggregate() [4/14]

template<typename source_t , typename accumulate_t , typename func_t >
static accumulate_t xtd::linq::enumerable::aggregate ( const xtd::collections::generic::ienumerable< source_t > &  source,
const accumulate_t &  seed,
const func_t &  func 
)
inlinestatic

Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value.

Parameters
sourceAn xtd::collections::generic::ienumerable <type_t> to aggregate over.
seedThe initial accumulator value.
funcAn accumulator function to be invoked on each element.
Returns
The final accumulator value.
Examples
The following code example demonstrates how to use xtd::linq::enumerable::aggregate to apply an accumulator function and use a seed value.
#include <xtd/linq/enumerable>
#include <xtd/array>
#include <xtd/console>
using namespace xtd;
using namespace xtd::linq;
auto main() -> int {
auto ints = array {4, 8, 8, 3, 9, 0, 7, 8, 2};
// Count the even numbers in the array, using a seed value of 0.
auto num_even = enumerable::aggregate(ints, 0, [](int total, int next) {
return next % 2 == 0 ? total + 1 : total;
});
console::write_line("The number of even integers is: {}", num_even);
}
// This code produces the following output :
//
// The number of even integers is: 6

◆ aggregate() [5/14]

template<typename source_t , typename accumulate_t , typename result_t >
static result_t xtd::linq::enumerable::aggregate ( const xtd::collections::generic::ienumerable< source_t > &  source,
const accumulate_t &  seed,
const xtd::func< accumulate_t, const source_t &, const accumulate_t & > &  func,
const xtd::func< result_t, const accumulate_t & > &  result_selector 
)
inlinestatic

Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.

Parameters
sourceAn xtd::collections::generic::ienumerable <type_t> to aggregate over.
seedThe initial accumulator value.
funcAn accumulator function to be invoked on each element.
result_SelectorA function to transform the final accumulator value into the result value.
Returns
The transformed final accumulator value.
Examples
The following code example demonstrates how to use xtd::linq::enumerable::aggregate to apply an accumulator function and use a seed value.
#include <xtd/linq/enumerable>
#include <xtd/array>
#include <xtd/console>
using namespace xtd;
using namespace xtd::linq;
auto main() -> int {
auto fruits = array {"apple"_s, "mango"_s, "orange"_s, "passionfruit"_s, "grape"_s};
// Determine whether any string in the array is longer than "banana".
auto longest_name =
enumerable::aggregate(fruits, "bananas"_s,
[](const string& longest, const string& next) {return next.length() > longest.length() ? next : longest;},
// Return the final result as an upper case string.
[](const string& fruit) {return fruit.to_upper();});
console::write_line("The fruit with the longest name is {}", longest_name);
}
// This code produces the following output :
//
// The fruit with the longest name is PASSIONFRUIT
basic_string to_upper() const noexcept
Returns a copy of the current xtd::basic_string converted to uppercase.
Definition basic_string.hpp:1953
size_type length() const noexcept
Gets the number of characters in the current xtd::basic_string object.
Definition basic_string.hpp:918

◆ aggregate() [6/14]

template<typename source_t , typename accumulate_t , typename result_t , typename func_t , typename result_selector_t >
static result_t xtd::linq::enumerable::aggregate ( const xtd::collections::generic::ienumerable< source_t > &  source,
const accumulate_t &  seed,
const func_t &  func,
const result_selector_t &  result_selector 
)
inlinestatic

Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.

Parameters
sourceAn xtd::collections::generic::ienumerable <type_t> to aggregate over.
seedThe initial accumulator value.
funcAn accumulator function to be invoked on each element.
result_selectorA function to transform the final accumulator value into the result value.
Returns
The transformed final accumulator value.
Examples
The following code example demonstrates how to use xtd::linq::enumerable::aggregate to apply an accumulator function and use a seed value.
#include <xtd/linq/enumerable>
#include <xtd/array>
#include <xtd/console>
using namespace xtd;
using namespace xtd::linq;
auto main() -> int {
auto fruits = array {"apple"_s, "mango"_s, "orange"_s, "passionfruit"_s, "grape"_s};
// Determine whether any string in the array is longer than "banana".
auto longest_name =
enumerable::aggregate(fruits, "bananas"_s,
[](const string& longest, const string& next) {return next.length() > longest.length() ? next : longest;},
// Return the final result as an upper case string.
[](const string& fruit) {return fruit.to_upper();});
console::write_line("The fruit with the longest name is {}", longest_name);
}
// This code produces the following output :
//
// The fruit with the longest name is PASSIONFRUIT

◆ aggregate() [7/14]

template<typename source_t , typename accumulate_t , typename func_t , typename result_selector_t >
static accumulate_t xtd::linq::enumerable::aggregate ( const xtd::collections::generic::ienumerable< source_t > &  source,
const accumulate_t &  seed,
const func_t &  func,
const result_selector_t &  result_selector 
)
inlinestatic

Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.

Parameters
sourceAn xtd::collections::generic::ienumerable <type_t> to aggregate over.
seedThe initial accumulator value.
funcAn accumulator function to be invoked on each element.
result_SelectorA function to transform the final accumulator value into the result value.
Returns
The transformed final accumulator value.
Examples
The following code example demonstrates how to use xtd::linq::enumerable::aggregate to apply an accumulator function and use a seed value.
#include <xtd/linq/enumerable>
#include <xtd/array>
#include <xtd/console>
using namespace xtd;
using namespace xtd::linq;
auto main() -> int {
auto fruits = array {"apple"_s, "mango"_s, "orange"_s, "passionfruit"_s, "grape"_s};
// Determine whether any string in the array is longer than "banana".
auto longest_name =
enumerable::aggregate(fruits, "bananas"_s,
[](const string& longest, const string& next) {return next.length() > longest.length() ? next : longest;},
// Return the final result as an upper case string.
[](const string& fruit) {return fruit.to_upper();});
console::write_line("The fruit with the longest name is {}", longest_name);
}
// This code produces the following output :
//
// The fruit with the longest name is PASSIONFRUIT

◆ aggregate() [8/14]

template<typename accumulate_t , typename input_iterator_t >
static accumulate_t xtd::linq::enumerable::aggregate ( input_iterator_t  first,
input_iterator_t  last,
const xtd::func< accumulate_t, const accumulate_t &, const accumulate_t & > &  func 
)
inlinestatic

Applies an accumulator function over a sequence.

Parameters
firstThe first iterator.
lastThe last iterator.
funcAn accumulator function to be invoked on each element.
Returns
The final accumulator value.
Examples
The following code example demonstrates how to reverse the order of words in a string by using enumerable::aggregate.
#include <xtd/linq/enumerable>
#include <xtd/console>
using namespace xtd;
using namespace xtd::linq;
auto main() -> int {
auto sentence = "the quick brown fox jumps over the lazy dog"_s;
// Split the string into individual words.
auto words = sentence.split(' ');
// Prepend each word to the beginning of the new sentence to reverse the word order.
auto reversed = enumerable::aggregate<string>(words.begin(), words.end(), [](const string& working_sentence, const string& next) {
return next + " " + working_sentence;
});
console::write_line(reversed.quoted());
}
// This code produces the following output :
//
// "dog lazy the over jumps fox brown quick the"

◆ aggregate() [9/14]

template<typename accumulate_t , typename input_iterator_t , typename func_t >
static accumulate_t xtd::linq::enumerable::aggregate ( input_iterator_t  first,
input_iterator_t  last,
const func_t &  func 
)
inlinestatic

Applies an accumulator function over a sequence.

Parameters
firstThe first iterator.
lastThe last iterator.
funcAn accumulator function to be invoked on each element.
Returns
The final accumulator value.
Examples
The following code example demonstrates how to reverse the order of words in a string by using xtd::linq::enumerable::aggregate.
#include <xtd/linq/enumerable>
#include <xtd/console>
using namespace xtd;
using namespace xtd::linq;
auto main() -> int {
auto sentence = "the quick brown fox jumps over the lazy dog"_s;
// Split the string into individual words.
auto words = sentence.split(' ');
// Prepend each word to the beginning of the new sentence to reverse the word order.
auto reversed = enumerable::aggregate<string>(words.begin(), words.end(), [](const string& working_sentence, const string& next) {
return next + " " + working_sentence;
});
console::write_line(reversed.quoted());
}
// This code produces the following output :
//
// "dog lazy the over jumps fox brown quick the"

◆ aggregate() [10/14]

template<typename accumulate_t , typename input_iterator_t >
static accumulate_t xtd::linq::enumerable::aggregate ( input_iterator_t  first,
input_iterator_t  last,
const accumulate_t &  seed,
const xtd::func< accumulate_t, const accumulate_t &, const accumulate_t & > &  func 
)
inlinestatic

Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value.

Parameters
sourceAn xtd::collections::generic::ienumerable <type_t> to aggregate over.
seedThe initial accumulator value.
funcAn accumulator function to be invoked on each element.
Returns
The final accumulator value.
Examples
The following code example demonstrates how to use xtd::linq::enumerable::aggregate to apply an accumulator function and use a seed value.
#include <xtd/linq/enumerable>
#include <xtd/array>
#include <xtd/console>
using namespace xtd;
using namespace xtd::linq;
auto main() -> int {
auto ints = array {4, 8, 8, 3, 9, 0, 7, 8, 2};
// Count the even numbers in the array, using a seed value of 0.
auto num_even = enumerable::aggregate(ints.begin(), ints.end(), 0, [](int total, int next) {
return next % 2 == 0 ? total + 1 : total;
});
console::write_line("The number of even integers is: {}", num_even);
}
// This code produces the following output :
//
// The number of even integers is: 6

◆ aggregate() [11/14]

template<typename accumulate_t , typename input_iterator_t , typename func_t >
static accumulate_t xtd::linq::enumerable::aggregate ( input_iterator_t  first,
input_iterator_t  last,
const accumulate_t &  seed,
const func_t &  func 
)
inlinestatic

Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value.

Parameters
firstThe first iterator.
lastThe last iterator.
seedThe initial accumulator value.
funcAn accumulator function to be invoked on each element.
Returns
The final accumulator value.
Examples
The following code example demonstrates how to use xtd::linq::enumerable::aggregate to apply an accumulator function and use a seed value.
#include <xtd/linq/enumerable>
#include <xtd/array>
#include <xtd/console>
using namespace xtd;
using namespace xtd::linq;
auto main() -> int {
auto ints = array {4, 8, 8, 3, 9, 0, 7, 8, 2};
// Count the even numbers in the array, using a seed value of 0.
auto num_even = enumerable::aggregate(ints.begin(), ints.end(), 0, [](int total, int next) {
return next % 2 == 0 ? total + 1 : total;
});
console::write_line("The number of even integers is: {}", num_even);
}
// This code produces the following output :
//
// The number of even integers is: 6

◆ aggregate() [12/14]

template<typename accumulate_t , typename result_t , typename input_iterator_t >
static result_t xtd::linq::enumerable::aggregate ( input_iterator_t  first,
input_iterator_t  last,
const accumulate_t &  seed,
const xtd::func< accumulate_t, const accumulate_t &, const accumulate_t & > &  func,
const xtd::func< result_t, const accumulate_t & > &  result_selector 
)
inlinestatic

Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.

Parameters
firstThe first iterator.
lastThe last iterator.
seedThe initial accumulator value.
funcAn accumulator function to be invoked on each element.
result_SelectorA function to transform the final accumulator value into the result value.
Returns
The transformed final accumulator value.
Examples
The following code example demonstrates how to use xtd::linq::enumerable::aggregate to apply an accumulator function and use a seed value.
#include <xtd/linq/enumerable>
#include <xtd/array>
#include <xtd/console>
using namespace xtd;
using namespace xtd::linq;
auto main() -> int {
auto ints = array {4, 8, 8, 3, 9, 0, 7, 8, 2};
// Count the even numbers in the array, using a seed value of 0.
auto num_even = enumerable::aggregate(ints.begin(), ints.end(), 0, [](int total, int next) {
return next % 2 == 0 ? total + 1 : total;
});
console::write_line("The number of even integers is: {}", num_even);
}
// This code produces the following output :
//
// The number of even integers is: 6

◆ aggregate() [13/14]

template<typename accumulate_t , typename result_t , typename input_iterator_t , typename func_t , typename result_selector_t >
static result_t xtd::linq::enumerable::aggregate ( input_iterator_t  first,
input_iterator_t  last,
const accumulate_t &  seed,
const func_t &  func,
const result_selector_t &  result_selector 
)
inlinestatic

Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.

Parameters
firstThe first iterator.
lastThe last iterator.
seedThe initial accumulator value.
funcAn accumulator function to be invoked on each element.
result_selectorA function to transform the final accumulator value into the result value.
Returns
The transformed final accumulator value.
Examples
The following code example demonstrates how to use xtd::linq::enumerable::aggregate to apply an accumulator function and use a seed value.
#include <xtd/linq/enumerable>
#include <xtd/array>
#include <xtd/console>
using namespace xtd;
using namespace xtd::linq;
auto main() -> int {
auto fruits = array {"apple"_s, "mango"_s, "orange"_s, "passionfruit"_s, "grape"_s};
// Determine whether any string in the array is longer than "banana".
auto longest_name =
enumerable::aggregate(fruits.begin(), fruits.end(), "bananas"_s,
[](const string& longest, const string& next) {return next.length() > longest.length() ? next : longest;},
// Return the final result as an upper case string.
[](const string& fruit) {return fruit.to_upper();});
console::write_line("The fruit with the longest name is {}", longest_name);
}
// This code produces the following output :
//
// The fruit with the longest name is PASSIONFRUIT

◆ aggregate() [14/14]

template<typename accumulate_t , typename input_iterator_t , typename func_t , typename result_selector_t >
static accumulate_t xtd::linq::enumerable::aggregate ( input_iterator_t  first,
input_iterator_t  last,
const accumulate_t &  seed,
const func_t &  func,
const result_selector_t &  result_selector 
)
inlinestatic

Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.

Parameters
firstThe first iterator.
lastThe last iterator.
seedThe initial accumulator value.
funcAn accumulator function to be invoked on each element.
result_selectorA function to transform the final accumulator value into the result value.
Returns
The transformed final accumulator value.
Examples
The following code example demonstrates how to use xtd::linq::enumerable::aggregate to apply an accumulator function and use a seed value.
#include <xtd/linq/enumerable>
#include <xtd/array>
#include <xtd/console>
using namespace xtd;
using namespace xtd::linq;
auto main() -> int {
auto fruits = array {"apple"_s, "mango"_s, "orange"_s, "passionfruit"_s, "grape"_s};
// Determine whether any string in the array is longer than "banana".
auto longest_name =
enumerable::aggregate(fruits.begin(), fruits.end(), "bananas"_s,
[](const string& longest, const string& next) {return next.length() > longest.length() ? next : longest;},
// Return the final result as an upper case string.
[](const string& fruit) {return fruit.to_upper();});
console::write_line("The fruit with the longest name is {}", longest_name);
}
// This code produces the following output :
//
// The fruit with the longest name is PASSIONFRUIT

◆ all() [1/4]

template<typename source_t >
static bool xtd::linq::enumerable::all ( const xtd::collections::generic::ienumerable< source_t > &  source,
const xtd::predicate< const source_t & > &  predicate 
)
inlinestatic

Determines whether all elements of a sequence satisfy a condition.

Parameters
sourceAn xtd::collections::generic::ienumerable <type_t> that contains the elements to apply the predicate to.
predicateA function to test each element for a condition.
Returns
true if every element of the source sequence passes the test in the specified predicate, or if the sequence is empty; otherwise, false.
Examples
The following code example demonstrates how to use xtd::linq::enumerable::all <source_t> to determine whether all the elements in a sequence satisfy a condition. Variable all_start_with_B is true if all the pet names start with "B" or if the pets array is empty.
#include <xtd/linq/enumerable>
#include <xtd/console>
using namespace xtd;
using namespace xtd::linq;
auto main() -> int {
struct pet : public object {
pet() = default;
pet(const string& name, int age) : name {name}, age {age} {}
string name;
int age = 0;
};
// Create an array of pets.
auto pets = array {
pet {"Barley", 10},
pet {"Boots", 4},
pet {"Whiskers", 6}
};
// Determine whether all pet names in the array start with 'B'.
bool all_start_with_b = enumerable::all(pets, [](const pet& pet) {
return pet.name.starts_with("B");
});
console::write_line("{} pet names start with 'B'.", all_start_with_b ? "All" : "Not all");
}
// This code produces the following output :
//
// Not all pet names start with 'B'.
static bool all(const xtd::collections::generic::ienumerable< source_t > &source, const xtd::predicate< const source_t & > &predicate)
Determines whether all elements of a sequence satisfy a condition.
Definition enumerable.hpp:241
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:42

◆ all() [2/4]

template<typename source_t , typename predicate_t >
static bool xtd::linq::enumerable::all ( const xtd::collections::generic::ienumerable< source_t > &  source,
const predicate_t &  predicate 
)
inlinestatic

Determines whether all elements of a sequence satisfy a condition.

Parameters
sourceAn xtd::collections::generic::ienumerable <type_t> that contains the elements to apply the predicate to.
predicateA function to test each element for a condition.
Returns
true if every element of the source sequence passes the test in the specified predicate, or if the sequence is empty; otherwise, false.
Examples
The following code example demonstrates how to use xtd::linq::enumerable::all <source_t> to determine whether all the elements in a sequence satisfy a condition. Variable all_start_with_B is true if all the pet names start with "B" or if the pets array is empty.
#include <xtd/linq/enumerable>
#include <xtd/console>
using namespace xtd;
using namespace xtd::linq;
auto main() -> int {
struct pet : public object {
pet() = default;
pet(const string& name, int age) : name {name}, age {age} {}
string name;
int age = 0;
};
// Create an array of pets.
auto pets = array {
pet {"Barley", 10},
pet {"Boots", 4},
pet {"Whiskers", 6}
};
// Determine whether all pet names in the array start with 'B'.
bool all_start_with_b = enumerable::all(pets, [](const pet& pet) {
return pet.name.starts_with("B");
});
console::write_line("{} pet names start with 'B'.", all_start_with_b ? "All" : "Not all");
}
// This code produces the following output :
//
// Not all pet names start with 'B'.

◆ all() [3/4]

template<typename source_t , typename input_iterator_t >
static bool xtd::linq::enumerable::all ( input_iterator_t  first,
input_iterator_t  last,
const xtd::predicate< const source_t & > &  predicate 
)
inlinestatic

Determines whether all elements of a sequence satisfy a condition.

Parameters
firstThe first iterator.
lastThe last iterator.
predicateA function to test each element for a condition.
Returns
true if every element of the source sequence passes the test in the specified predicate, or if the sequence is empty; otherwise, false.
Examples
The following code example demonstrates how to use xtd::linq::enumerable::all <source_t> to determine whether all the elements in a sequence satisfy a condition. Variable all_start_with_B is true if all the pet names start with "B" or if the pets array is empty.
#include <xtd/linq/enumerable>
#include <xtd/console>
using namespace xtd;
using namespace xtd::linq;
auto main() -> int {
struct pet : public object {
pet() = default;
pet(const string& name, int age) : name {name}, age {age} {}
string name;
int age = 0;
};
// Create an array of pets.
auto pets = array {
pet {"Barley", 10},
pet {"Boots", 4},
pet {"Whiskers", 6}
};
// Determine whether all pet names in the array start with 'B'.
bool all_start_with_b = enumerable::all(pets, [](const pet& pet) {
return pet.name.starts_with("B");
});
console::write_line("{} pet names start with 'B'.", all_start_with_b ? "All" : "Not all");
}
// This code produces the following output :
//
// Not all pet names start with 'B'.

◆ all() [4/4]

template<typename source_t , typename input_iterator_t , typename predicate_t >
static bool xtd::linq::enumerable::all ( input_iterator_t  first,
input_iterator_t  last,
const predicate_t &  predicate 
)
inlinestatic

Determines whether all elements of a sequence satisfy a condition.

Parameters
firstThe first iterator.
lastThe last iterator.
predicateA function to test each element for a condition.
Returns
true if every element of the source sequence passes the test in the specified predicate, or if the sequence is empty; otherwise, false.
Examples
The following code example demonstrates how to use xtd::linq::enumerable::all <source_t> to determine whether all the elements in a sequence satisfy a condition. Variable all_start_with_B is true if all the pet names start with "B" or if the pets array is empty.
#include <xtd/linq/enumerable>
#include <xtd/console>
using namespace xtd;
using namespace xtd::linq;
auto main() -> int {
struct pet : public object {
pet() = default;
pet(const string& name, int age) : name {name}, age {age} {}
string name;
int age = 0;
};
// Create an array of pets.
auto pets = array {
pet {"Barley", 10},
pet {"Boots", 4},
pet {"Whiskers", 6}
};
// Determine whether all pet names in the array start with 'B'.
bool all_start_with_b = enumerable::all<pet>(pets.begin(), pets.end(), [](const pet& pet) {
return pet.name.starts_with("B");
});
console::write_line("{} pet names start with 'B'.", all_start_with_b ? "All" : "Not all");
}
// This code produces the following output :
//
// Not all pet names start with 'B'.

◆ any() [1/6]

template<typename source_t >
static bool xtd::linq::enumerable::any ( const xtd::collections::generic::ienumerable< source_t > &  source)
inlinestatic

Determines whether a sequence contains any elements.

Parameters
firstThe first iterator.
lastThe last iterator.
Returns
true if the source sequence contains any elements; otherwise, false.
Examples
The following code example demonstrates how to use Any to determine whether a sequence contains any elements.

◆ any() [2/6]

template<typename source_t >
static bool xtd::linq::enumerable::any ( const xtd::collections::generic::ienumerable< source_t > &  source,
const xtd::predicate< const source_t & > &  predicate 
)
inlinestatic

Determines whether any element of a sequence satisfies a condition.

Parameters
sourceAn xtd::collections::generic::ienumerable <type_t> that contains the elements to apply the predicate to.
predicateA function to test each element for a condition.
Returns
true if every element of the source sequence passes the test in the specified predicate, or if the sequence is empty; otherwise, false.
Examples
The following code example demonstrates how to use xtd::linq::enumerable::all <source_t> to determine whether all the elements in a sequence satisfy a condition. Variable all_start_with_B is true if all the pet names start with "B" or if the pets array is empty.
#include <xtd/linq/enumerable>
#include <xtd/console>
using namespace xtd;
using namespace xtd::linq;
auto main() -> int {
struct pet : public object {
pet() = default;
pet(const string& name, int age) : name {name}, age {age} {}
string name;
int age = 0;
};
// Create an array of pets.
auto pets = array {
pet {"Barley", 10},
pet {"Boots", 4},
pet {"Whiskers", 6}
};
// Determine whether all pet names in the array start with 'B'.
bool all_start_with_b = enumerable::all(pets, [](const pet& pet) {
return pet.name.starts_with("B");
});
console::write_line("{} pet names start with 'B'.", all_start_with_b ? "All" : "Not all");
}
// This code produces the following output :
//
// Not all pet names start with 'B'.

◆ any() [3/6]

template<typename source_t , typename predicate_t >
static bool xtd::linq::enumerable::any ( const xtd::collections::generic::ienumerable< source_t > &  source,
const predicate_t &  predicate 
)
inlinestatic

Determines whether any elements of a sequence satisfy a condition.

Parameters
sourceAn xtd::collections::generic::ienumerable <type_t> that contains the elements to apply the predicate to.
predicateA function to test each element for a condition.
Returns
true if every element of the source sequence passes the test in the specified predicate, or if the sequence is empty; otherwise, false.
Examples
The following code example demonstrates how to use xtd::linq::enumerable::all <source_t> to determine whether all the elements in a sequence satisfy a condition. Variable all_start_with_B is true if all the pet names start with "B" or if the pets array is empty.
#include <xtd/linq/enumerable>
#include <xtd/console>
using namespace xtd;
using namespace xtd::linq;
auto main() -> int {
struct pet : public object {
pet() = default;
pet(const string& name, int age) : name {name}, age {age} {}
string name;
int age = 0;
};
// Create an array of pets.
auto pets = array {
pet {"Barley", 10},
pet {"Boots", 4},
pet {"Whiskers", 6}
};
// Determine whether all pet names in the array start with 'B'.
bool all_start_with_b = enumerable::all(pets, [](const pet& pet) {
return pet.name.starts_with("B");
});
console::write_line("{} pet names start with 'B'.", all_start_with_b ? "All" : "Not all");
}
// This code produces the following output :
//
// Not all pet names start with 'B'.

◆ any() [4/6]

template<typename source_t , typename input_iterator_t >
static bool xtd::linq::enumerable::any ( input_iterator_t  first,
input_iterator_t  last 
)
inlinestatic

Determines whether a sequence contains any elements.

Parameters
firstThe first iterator.
lastThe last iterator.
Returns
true if the source sequence contains any elements; otherwise, false.
Examples
The following code example demonstrates how to use Any to determine whether a sequence contains any elements.

◆ any() [5/6]

template<typename source_t , typename input_iterator_t >
static bool xtd::linq::enumerable::any ( input_iterator_t  first,
input_iterator_t  last,
const xtd::predicate< const source_t & > &  predicate 
)
inlinestatic

Determines whether any elements of a sequence satisfy a condition.

Parameters
firstThe first iterator.
lastThe last iterator.
predicateA function to test each element for a condition.
Returns
true if every element of the source sequence passes the test in the specified predicate, or if the sequence is empty; otherwise, false.
Examples
The following code example demonstrates how to use xtd::linq::enumerable::all <source_t> to determine whether all the elements in a sequence satisfy a condition. Variable all_start_with_B is true if all the pet names start with "B" or if the pets array is empty.
#include <xtd/linq/enumerable>
#include <xtd/console>
using namespace xtd;
using namespace xtd::linq;
auto main() -> int {
struct pet : public object {
pet() = default;
pet(const string& name, int age) : name {name}, age {age} {}
string name;
int age = 0;
};
// Create an array of pets.
auto pets = array {
pet {"Barley", 10},
pet {"Boots", 4},
pet {"Whiskers", 6}
};
// Determine whether all pet names in the array start with 'B'.
bool all_start_with_b = enumerable::all(pets, [](const pet& pet) {
return pet.name.starts_with("B");
});
console::write_line("{} pet names start with 'B'.", all_start_with_b ? "All" : "Not all");
}
// This code produces the following output :
//
// Not all pet names start with 'B'.

◆ any() [6/6]

template<typename source_t , typename input_iterator_t , typename predicate_t >
static bool xtd::linq::enumerable::any ( input_iterator_t  first,
input_iterator_t  last,
const predicate_t &  predicate 
)
inlinestatic

Determines whether any elements of a sequence satisfy a condition.

Parameters
sourceAn xtd::collections::generic::ienumerable <type_t> that contains the elements to apply the predicate to.
predicateA function to test each element for a condition.
Returns
true if every element of the source sequence passes the test in the specified predicate, or if the sequence is empty; otherwise, false.
Examples
The following code example demonstrates how to use xtd::linq::enumerable::all <source_t> to determine whether all the elements in a sequence satisfy a condition. Variable all_start_with_B is true if all the pet names start with "B" or if the pets array is empty.
#include <xtd/linq/enumerable>
#include <xtd/console>
using namespace xtd;
using namespace xtd::linq;
auto main() -> int {
struct pet : public object {
pet() = default;
pet(const string& name, int age) : name {name}, age {age} {}
string name;
int age = 0;
};
// Create an array of pets.
auto pets = array {
pet {"Barley", 10},
pet {"Boots", 4},
pet {"Whiskers", 6}
};
// Determine whether all pet names in the array start with 'B'.
bool all_start_with_b = enumerable::all<pet>(pets.begin(), pets.end(), [](const pet& pet) {
return pet.name.starts_with("B");
});
console::write_line("{} pet names start with 'B'.", all_start_with_b ? "All" : "Not all");
}
// This code produces the following output :
//
// Not all pet names start with 'B'.

The documentation for this class was generated from the following file: