std::set_union
|
|
Esta página se ha traducido por ordenador/computador/computadora de la versión en inglés de la Wiki usando Google Translate.
La traducción puede contener errores y palabras aparatosas/incorrectas. Planea sobre el texto para ver la versión original. Puedes ayudar a corregir los errores y mejorar la traducción. Para instrucciones haz clic aquí. |
| Definido en el archivo de encabezado <algorithm>
|
||
template< class InputIt1, class InputIt2, class OutputIt > OutputIt set_union( InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt d_first ); |
(1) | |
template< class InputIt1, class InputIt2, class OutputIt, class Compare > OutputIt set_union( InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt d_first, Compare comp ); |
(2) | |
d_first que consiste de todos los elementos presentes en uno o ambos rangos según [first1, last1) y [first2, last2). La primera versión espera tanto de entrada va a ser resuelto con operator<, la segunda versión espera que se solucionó con la comparación comp función dada. Si algún elemento se encuentra m veces en [first1, last1) y n veces en [first2, last2), entonces todos los elementos m se copiarán desde [first1, last1) a d_first, preservar el orden y haga exactamente std::max(n-m, 0) elementos se copiarán desde [first2, last2) a d_first, también preservar el orden. El rango resultante no se puede solapar con cualquiera de los rangos de entrada .d_first consisting of all elements present in one or both sorted ranges [first1, last1) and [first2, last2). The first version expects both input ranges to be sorted with operator<, the second version expects them to be sorted with the given comparison function comp. If some element is found m times in [first1, last1) and n times in [first2, last2), then all m elements will be copied from [first1, last1) to d_first, preserving order, and then exactly std::max(n-m, 0) elements will be copied from [first2, last2) to d_first, also preserving order. The resulting range cannot overlap with either of the input ranges.You can help to correct and verify the translation. Click here for instructions.
Parámetros
| first1, last1 | - | la primera entrada ordenados rango
Original: the first input sorted range The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| first2, last2 | - | la segunda entrada ordenada rango
Original: the second input sorted range The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| comp | - | objeto función de comparación (es decir, un objeto que satisface los requerimientos de Compare) que devuelve true si el primer argumento es menor que el segundo. La signatura de la función de comparación deberá ser equivalente a lo siguiente:
Mientras que la signatura no necesita ser |
| Requisitos de tipo | ||
-InputIt1 debe reunir los requerimientos de InputIterator.
| ||
-InputIt2 debe reunir los requerimientos de InputIterator.
| ||
-OutputIt debe reunir los requerimientos de OutputIterator.
| ||
Valor de retorno
You can help to correct and verify the translation. Click here for instructions.
Complejidad
= std::distance(first1, last1) y N2 = std::distance(first2, last2) .= std::distance(first1, last1) and N2 = std::distance(first2, last2).You can help to correct and verify the translation. Click here for instructions.
Posible implementación
| Primera versión |
|---|
template<class InputIt1, class InputIt2, class OutputIt>
OutputIt set_union(InputIt1 first1, InputIt1 last1,
InputIt2 first2, InputIt2 last2,
OutputIt d_first)
{
for (; first1 != last1; ++d_first) {
if (first2 == last2)
return std::copy(first1, last1, d_first);
if (*first2 < *first1) {
*d_first = *first2++;
} else {
*d_first = *first1;
if (!(*first1 < *first2))
++first2;
++first1;
}
}
return std::copy(first2, last2, d_first);
}
|
| Segunda versión |
template<class InputIt1, class InputIt2,
class OutputIt, class Compare>
OutputIt set_union(InputIt1 first1, InputIt1 last1,
InputIt2 first2, InputIt2 last2,
OutputIt d_first, Compare comp)
{
for (; first1 != last1; ++d_first) {
if (first2 == last2)
return std::copy(first1, last1, d_first);
if (comp(*first2, *first1)) {
*d_first = *first2++;
} else {
*d_first = *first1;
if (!comp(*first1, *first2))
++first2;
++first1;
}
}
return std::copy(first2, last2, d_first);
}
|
Ejemplo
| Esta sección está incompleta Razón: sin ejemplo |
Ver también
Devuelve true si una secuencia es una subsecuencia de otra. (plantilla de función) | |
| Calcula la diferencia entre dos conjuntos. (plantilla de función) | |
| Calcula la intersección de dos conjuntos. (plantilla de función) | |
| Calcula la diferencia simétrica entre dos conjuntos. (plantilla de función) |