a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
StdVectorFiller.hpp
Go to the documentation of this file.
1/*
2 * StdVectorFiller.hpp
3 *
4 * Created on: Jan 20, 2012
5 * Author: Ben O'Leary (benjamin.oleary@gmail.com)
6 *
7 * This file is part of BOLlib, released under the
8 * GNU General Public License. Please see the accompanying
9 * README.BOLlib.txt file for a full list of files, brief documentation
10 * on how to use these classes, and further details on the license.
11 */
12
13#ifndef STDVECTORFILLER_HPP_
14#define STDVECTORFILLER_HPP_
15
16#include <vector>
17#include <string>
18
19namespace BOL
20{
21 /* this is a template class just to make it easier to initialize a
22 * std::vector with a heterogeneous initial set of elements. the constructor
23 * takes the first element of the vector as its argument, & subsequent
24 * elements are added with operator(), which returns a reference to this
25 * instance, so that the operator() calls can be chained, & then a reference
26 * to its internal temporary std::vector< StoredClass > is returned with
27 * v( StoredClass const& ), which takes the final element as its argument.
28 * hence for example one could have:
29 * std::vector< int > const
30 * constantOneToFive( BOL::StdVectorFiller( 1 )( 2 )( 3 )( 4 ).end( 5 ) );
31 */
32 template< typename StoredClass >
34 {
35 public:
36 StdVectorFiller( StoredClass const& firstElement );
38
40 operator()( StoredClass const& nextElement );
41 std::vector< StoredClass > const&
42 end( StoredClass const& lastElement );
43 std::vector< StoredClass > const&
44 e( StoredClass const& lastElement ) { return end( lastElement ); }
45
46
47 protected:
48 std::vector< StoredClass > stdVector;
49 };
54 // these probably shouldn't be used, but they save space...
55 // e.g. std::vector< int > const oneToFour( BOL::Vi( 1 )( 2 )( 3 ).e( 4 ) );
56
57
58
59 template< typename StoredClass >
60 inline
62 StoredClass const& firstElement ) :
63 stdVector( 1,
64 firstElement )
65 {
66 // just an initialization list.
67 }
68
69 template< typename StoredClass >
70 inline
72 {
73 // does nothing.
74 }
75
76
77 template< typename StoredClass >
79 StdVectorFiller< StoredClass >::operator()( StoredClass const& nextElement )
80 {
81 stdVector.push_back( nextElement );
82 return *this;
83 }
84
85 template< typename StoredClass >
86 inline std::vector< StoredClass > const&
87 StdVectorFiller< StoredClass >::end( StoredClass const& lastElement )
88 {
89 stdVector.push_back( lastElement );
90 return stdVector;
91 }
92
93}
94
95#endif /* STDVECTORFILLER_HPP_ */
StdVectorFiller(StoredClass const &firstElement)
StdVectorFiller & operator()(StoredClass const &nextElement)
std::vector< StoredClass > stdVector
std::vector< StoredClass > const & end(StoredClass const &lastElement)
std::vector< StoredClass > const & e(StoredClass const &lastElement)
StdVectorFiller< double > Vd
StdVectorFiller< int > Vi
StdVectorFiller< bool > Vb
StdVectorFiller< std::string > Vs