GetFEM  5.4.2
bgeot_comma_init.h
Go to the documentation of this file.
1 /* -*- c++ -*- (enables emacs c++ mode) */
2 /*===========================================================================
3 
4  Copyright (C) 2003-2020 Julien Pommier
5 
6  This file is a part of GetFEM
7 
8  GetFEM is free software; you can redistribute it and/or modify it
9  under the terms of the GNU Lesser General Public License as published
10  by the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version along with the GCC Runtime Library
12  Exception either version 3.1 or (at your option) any later version.
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16  License and GCC Runtime Library Exception for more details.
17  You should have received a copy of the GNU Lesser General Public License
18  along with this program; if not, write to the Free Software Foundation,
19  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20 
21  As a special exception, you may use this file as it is a part of a free
22  software library without restriction. Specifically, if other files
23  instantiate templates or use macros or inline functions from this file,
24  or you compile this file and link it with other files to produce an
25  executable, this file does not by itself cause the resulting executable
26  to be covered by the GNU Lesser General Public License. This exception
27  does not however invalidate any other reasons why the executable file
28  might be covered by the GNU Lesser General Public License.
29 
30 ===========================================================================*/
31 
32 /**@file bgeot_comma_init.h
33  @author Julien Pommier <Julien.Pommier@insa-toulouse.fr>
34  @date March 27, 2003.
35  @brief convenient initialization of vectors via overload of "operator,".
36  @code
37  std::vector<double> foo; bgeot::sc(foo) += 1,3,4;
38  @endcode
39 
40  highly inspired by the boost init.hpp (C) Thorsten Ottosen
41  (http://www.cs.auc.dk/~nesotto/init/)
42 */
43 #ifndef COMMA_INIT
44 #define COMMA_INIT
45 
46 namespace bgeot {
47 
48  /**
49  * Template class which forwards insertions to the
50  * container class.
51  */
52  template<typename Container> class Comma_initializer {
53  typedef typename Container::value_type value_type;
54  Container& c_;
55  public:
56  explicit Comma_initializer( Container& c ) : c_( c ) {}
57 
58  Comma_initializer& operator,(const value_type& v) {
59  c_.push_back(v);
60  return *this;
61  }
62 
63  /**
64  * Should only be used with first value. The operator
65  * gives a nice syntax for initializing the container.
66  */
67  Comma_initializer& operator=(const value_type v) {
68  c_.clear();
69  c_.push_back(v);
70  return *this;
71  }
72  /**
73  * Should only be used with first value. The operator
74  * gives a nice syntax for appending to the container.
75  */
76  Comma_initializer& operator+=(value_type v) {
77  c_.push_back(v);
78  return *this;
79  }
80  };
81 
82  template<typename T> Comma_initializer<T> sc( T& c )
83  { return Comma_initializer<T>(c); }
84 
85 }
86 
87 #endif
bgeot::Comma_initializer::operator+=
Comma_initializer & operator+=(value_type v)
Should only be used with first value.
Definition: bgeot_comma_init.h:76
bgeot::Comma_initializer
Template class which forwards insertions to the container class.
Definition: bgeot_comma_init.h:52
bgeot
Basic Geometric Tools.
Definition: bgeot_convex_ref.cc:27
bgeot::Comma_initializer::operator=
Comma_initializer & operator=(const value_type v)
Should only be used with first value.
Definition: bgeot_comma_init.h:67

Rabisu Mirror Service We provide mirrors to support Open source communities. Our mirror server is located in Istanbul/Turkey region.

Please do not hesitate to contact mirror@rabisu.com for new open source mirror submissions.