C++QEDCore  2.100.2 (v2 Milestone 10 Development branch)
a framework for simulating open quantum dynamics – core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Algorithm.h
Go to the documentation of this file.
1 // Copyright András Vukics 2006–2014. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.txt)
3 // -*- C++ -*-
4 #ifndef CPPQEDCORE_UTILS_ALGORITHM_H_INCLUDED
5 #define CPPQEDCORE_UTILS_ALGORITHM_H_INCLUDED
6 
7 #include <boost/range/numeric.hpp>
8 
9 
10 namespace cpputils {
11 
12 
14 template<typename SeqOfSeqs, typename Out_Iterator>
15 const Out_Iterator
16 concatenateViaIterator(const SeqOfSeqs& sOs,
17  Out_Iterator out)
18 {
19  struct Helper
20  {
21  static const Out_Iterator _(Out_Iterator iter, const typename SeqOfSeqs::value_type& t) {return std::copy(t.begin(),t.end(),iter);}
22  };
23 
24  return boost::accumulate(sOs,out,Helper::_);
25 }
26 
27 
29 template<typename SeqOfSeqs, typename Out>
30 const Out&
31 concatenate(const SeqOfSeqs& sOs,
32  Out&& out)
33 {
34  concatenateViaIterator(sOs,out.begin());
35  return out;
36 }
37 
38 
40 template<typename Out, typename SeqOfSeqs>
41 const Out
42 concatenateGrow(const SeqOfSeqs& sOs)
43 {
44  Out empty;
45  concatenateViaIterator(sOs,std::back_inserter(empty));
46  return empty;
47 }
48 
49 
50 } // cpputils
51 
52 
53 #endif // CPPQEDCORE_UTILS_ALGORITHM_H_INCLUDED
const Out concatenateGrow(const SeqOfSeqs &sOs)
Fills an empty (default-constructed) container with concatenated values taken subsequently from the i...
Definition: Algorithm.h:42
const Out_Iterator concatenateViaIterator(const SeqOfSeqs &sOs, Out_Iterator out)
Fills a container by output iterator with concatenated values taken subsequently from the input seque...
Definition: Algorithm.h:16
Namespace comprising otherwise hard-to-classify generic utilities.
Definition: Algorithm.h:10
const Out & concatenate(const SeqOfSeqs &sOs, Out &&out)
Fills a container of the necessary size with concatenated values taken subsequently from the input se...
Definition: Algorithm.h:31