comparison lib/swig/swigwin-2.0.11/Lib/std/std_carray.swg @ 1899:b3009adc0e2f

Adding swig, gitignore, hgignore
author Nomad
date Mon, 21 Oct 2013 10:42:27 +0200
parents
children
comparison
equal deleted inserted replaced
1867:eb580660bbbb 1899:b3009adc0e2f
1 %{
2 #include <algorithm>
3 %}
4
5 //
6 // std::carray - is really an extension to the 'std' namespace.
7 //
8 // A simple fix C array wrapper, more or less as presented in
9 //
10 // "The C++ Standarf Library", by Nicolai M. Josuttis
11 //
12 // which is also derived from the example in
13 //
14 // "The C++ Programming Language", by Bjarne Stroustup.
15 //
16
17 %inline %{
18 namespace std {
19 template <class _Type, size_t _Size>
20 class carray
21 {
22 public:
23 typedef _Type value_type;
24 typedef size_t size_type;
25
26 typedef _Type * iterator;
27 typedef const _Type * const_iterator;
28
29 carray() { }
30
31 carray(const carray& c) {
32 std::copy(c.v, c.v + size(), v);
33 }
34
35 template <class _Iterator>
36 carray(_Iterator first, _Iterator last) {
37 assign(first, last);
38 }
39
40 iterator begin() { return v; }
41 iterator end() { return v + _Size; }
42
43 const_iterator begin() const { return v; }
44 const_iterator end() const { return v + _Size; }
45
46 _Type& operator[](size_t i) { return v[i]; }
47 const _Type& operator[](size_t i) const { return v[i]; }
48
49 static size_t size() { return _Size; }
50
51 template <class _Iterator>
52 void assign(_Iterator first, _Iterator last) {
53 if (std::distance(first,last) == size()) {
54 std::copy(first, last, v);
55 } else {
56 throw std::length_error("bad range length");
57 }
58 }
59
60 private:
61 _Type v[_Size];
62 };
63 }
64 %}