Library of Assembled Shared Sources
extended_algorithm.h
Go to the documentation of this file.
1/** @file
2 * @author Bram de Greve (bram@cocamware.com)
3 * @author Tom De Muer (tom@cocamware.com)
4 *
5 * *** BEGIN LICENSE INFORMATION ***
6 *
7 * The contents of this file are subject to the Common Public Attribution License
8 * Version 1.0 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://lass.sourceforge.net/cpal-license. The License is based on the
11 * Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover
12 * use of software over a computer network and provide for limited attribution for
13 * the Original Developer. In addition, Exhibit A has been modified to be consistent
14 * with Exhibit B.
15 *
16 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
17 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
18 * language governing rights and limitations under the License.
19 *
20 * The Original Code is LASS - Library of Assembled Shared Sources.
21 *
22 * The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
23 * The Original Developer is the Initial Developer.
24 *
25 * All portions of the code written by the Initial Developer are:
26 * Copyright (C) 2004-2011 the Initial Developer.
27 * All Rights Reserved.
28 *
29 * Contributor(s):
30 *
31 * Alternatively, the contents of this file may be used under the terms of the
32 * GNU General Public License Version 2 or later (the GPL), in which case the
33 * provisions of GPL are applicable instead of those above. If you wish to allow use
34 * of your version of this file only under the terms of the GPL and not to allow
35 * others to use your version of this file under the CPAL, indicate your decision by
36 * deleting the provisions above and replace them with the notice and other
37 * provisions required by the GPL License. If you do not delete the provisions above,
38 * a recipient may use your version of this file under either the CPAL or the GPL.
39 *
40 * *** END LICENSE INFORMATION ***
41 */
42
43
44
45/** @defgroup extended_algorithm
46 * @brief extra algorithms
47 * @author Bram de Greve [BdG]
48 */
49
50#ifndef LASS_GUARDIAN_OF_INCLUSION_STDE_EXTENDED_ALGORITHM_H
51#define LASS_GUARDIAN_OF_INCLUSION_STDE_EXTENDED_ALGORITHM_H
52
53#include "stde_common.h"
54
55namespace lass
56{
57namespace stde
58{
59
60// --- pure iterator algorithms --------------------------------------------------------------------
61
62/** copy @a count elements from sequence starting at @a first to sequence starting at @a result
63 * @ingroup extended_algorithm
64 * @pre there should be enough room in output sequence to hold @a n elements
65 */
66template <class InputIterator, class Size, class OutputIterator>
67OutputIterator copy_n(InputIterator first, Size count,
68 OutputIterator result)
69{
70 for (Size i=0;i<count;++i)
71 *result++ = *first++;
72 return result;
73}
74
75/** copy sequence @a first to @a last @a n times to sequence starting at @a output
76 * @ingroup extended_algorithm
77 * @pre there should be enough room in output sequence to hold @a n times the input sequence.
78 */
79template <class InputIterator, class OutputIterator, class Size>
80OutputIterator repeat(InputIterator first, InputIterator last, OutputIterator output, Size n)
81{
82 for (Size i = 0; i < n; ++i)
83 {
84 output = std::copy(first, last, output);
85 }
86 return output;
87}
88
89
90// --- container algorithms shortcuts --------------------------------------------------------------
91
92/** @ingroup extended_algorithm
93 */
94template <class Container, class Size> inline
95Container repeat_c(const Container& iC, Size n)
96{
97 Container result;
98 repeat(iC.begin(), iC.end(), std::back_inserter(result), n);
99 return result;
100}
101
102/** @ingroup extended_algorithm
103 */
104template <class Container, class Size> inline
105Container& inplace_repeat_c(Container& iC, Size n)
106{
107 Container temp;
108 repeat(iC.begin(), iC.end(), std::back_inserter(temp), n);
109 iC.swap(temp);
110 return iC;
111}
112
113}
114}
115
116#endif
117
118// EOF
OutputIterator copy_n(InputIterator first, Size count, OutputIterator result)
copy count elements from sequence starting at first to sequence starting at result
OutputIterator repeat(InputIterator first, InputIterator last, OutputIterator output, Size n)
copy sequence first to last n times to sequence starting at output
lass extensions to the standard library
Library for Assembled Shared Sources.
Definition config.h:53