Rheolef  7.1
an efficient C++ finite element environment
vec_concat.h
Go to the documentation of this file.
1 #ifndef _RHEOLEF_VEC_CONCAT_H
2 #define _RHEOLEF_VEC_CONCAT_H
3 // build vec from initializer lists
24 //
25 #include "rheolef/vec.h"
26 
27 namespace rheolef { namespace details {
28 
29 // ----------------------------------------------------------------------------
30 // 1) implementation
31 // ----------------------------------------------------------------------------
32 
34 static int constraint_process_rank (const communicator& comm = communicator()) { return 0; }
35 
36 template <class T, class M>
37 class vec_concat_value {
38 public:
39 // typedef:
40  typedef enum { scalar, scalars, vector} variant_type;
41 // allocators:
42  template <class U,
43  class Sfinae
44  = typename std::enable_if<
46  ,void
47  >::type
48  >
49  vec_concat_value (const U& x) : s(x), ss(), v(), variant(scalar) {}
50  vec_concat_value (const std::vector<T>& x) : s(), ss(x), v(), variant(scalars) {}
51  vec_concat_value (const vec<T,M>& x) : s(), ss(), v(x), variant(vector) {}
52 // data:
53 public:
54  T s;
55  std::vector<T> ss;
58 };
59 
60 template <class T, class M>
61 class vec_concat {
62 public:
63 // typedef:
64  typedef typename vec<T,M>::size_type size_type;
66 
67 // allocators:
68 
69  vec_concat () : _l() {}
70  vec<T,M> build_vec() const;
71 
72  vec_concat (const std::initializer_list<value_type>& il) : _l() {
73  typedef typename std::initializer_list<value_type>::const_iterator const_iterator;
74  for (const_iterator iter = il.begin(); iter != il.end(); ++iter) {
75  _l.push_back(*iter);
76  }
77  }
78 
79 // data:
80 protected:
81  std::list<value_type> _l;
82 };
83 } // namespace details
84 
85 // ----------------------------------------------------------------------------
86 // 2) interface with the vec<T,M> class
87 // ----------------------------------------------------------------------------
88 template <class T, class M>
89 inline
90 int
92 {
93  return details::constraint_process_rank (base::comm());
94 }
95 template <class T, class M>
96 inline
97 vec<T,M>::vec (const std::initializer_list<details::vec_concat_value<T,M> >& init_list)
98 {
99  details::vec_concat<T,M> vc (init_list);
101 }
102 template <class T, class M>
103 inline
104 vec<T,M>&
105 vec<T,M>::operator= (const std::initializer_list<details::vec_concat_value<T,M> >& init_list)
106 {
107  details::vec_concat<T,M> vc (init_list);
109  return *this;
110 }
111 
112 } // namespace rheolef
113 #endif // _RHEOLEF_VEC_CONCAT_H
rheolef::vec::operator=
vec< T, M > & operator=(const vec< T, M > &x)
Definition: vec.h:175
rheolef::details::vec_concat::vec_concat
vec_concat()
Definition: vec_concat.h:69
rheolef::details::vec_concat::size_type
vec< T, M >::size_type size_type
Definition: vec_concat.h:64
rheolef::details::vec_concat_value::scalar
@ scalar
Definition: vec_concat.h:40
rheolef::details::vec_concat_value::s
T s
Definition: vec_concat.h:54
rheolef::details::vec_concat::build_vec
vec< T, M > build_vec() const
Definition: vec_concat.cc:29
rheolef::details::vec_concat_value::variant
variant_type variant
Definition: vec_concat.h:57
rheolef::details::vec_concat_value::ss
std::vector< T > ss
Definition: vec_concat.h:55
rheolef::details::vec_concat_value::vec_concat_value
vec_concat_value(const std::vector< T > &x)
Definition: vec_concat.h:50
rheolef::vec
see the vec page for the full documentation
Definition: vec.h:79
rheolef::details::vec_concat_value::scalars
@ scalars
Definition: vec_concat.h:40
rheolef::details::vec_concat_value::variant_type
variant_type
Definition: vec_concat.h:40
rheolef::details::vec_concat::_l
std::list< value_type > _l
Definition: vec_concat.h:81
rheolef::details::vec_concat::vec_concat
vec_concat(const std::initializer_list< value_type > &il)
Definition: vec_concat.h:72
rheolef::type
rheolef::std type
rheolef::details::vec_concat_value
Definition: vec.h:73
rheolef::details::vec_concat_value::vec_concat_value
vec_concat_value(const vec< T, M > &x)
Definition: vec_concat.h:51
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
rheolef::details::vec_concat::value_type
vec_concat_value< T, M > value_type
Definition: vec_concat.h:65
rheolef::vec::vec
vec(const vec< T, M > &)
Definition: vec.h:168
rheolef::const_iterator
Definition: field_expr_recursive.h:552
rheolef::details::vec_concat
Definition: vec_concat.h:61
rheolef::details::vec_concat_value::vec_concat_value
vec_concat_value(const U &x)
Definition: vec_concat.h:49
rheolef::details::is_rheolef_arithmetic
Definition: Float.h:150
rheolef::vec::constraint_process_rank
int constraint_process_rank() const
Definition: vec_concat.h:91
rheolef::details::vec_concat_value::vector
@ vector
Definition: vec_concat.h:40
rheolef::vec::size_type
base::size_type size_type
Definition: vec.h:86
rheolef::details::vec_concat_value::v
vec< T, M > v
Definition: vec_concat.h:56
T
Expr1::float_type T
Definition: field_expr.h:218