Commit c7fae41f51100c8939cff8001ca53bff03aa94b3

Authored by Grzegorz Jabłoński
1 parent a773e56f

constexpr and noexcept in vector template

examples11/04-vectortmpl/vector.h
@@ -11,7 +11,7 @@ template <class C> class vector { @@ -11,7 +11,7 @@ template <class C> class vector {
11 11
12 private: 12 private:
13 static unsigned int round_up_to_power_of_2(unsigned w) { 13 static unsigned int round_up_to_power_of_2(unsigned w) {
14 - const auto bits = std::numeric_limits<unsigned>::digits; 14 + constexpr auto bits = std::numeric_limits<unsigned>::digits;
15 --w; 15 --w;
16 for (unsigned s = 1; s < bits; s *= 2) 16 for (unsigned s = 1; s < bits; s *= 2)
17 w |= w >> s; 17 w |= w >> s;
@@ -105,7 +105,7 @@ public: @@ -105,7 +105,7 @@ public:
105 } 105 }
106 } 106 }
107 107
108 - void swap(vector<C> &s) { 108 + void swap(vector<C> &s) noexcept {
109 C *t1 = s.data; 109 C *t1 = s.data;
110 unsigned int t2 = s.size; 110 unsigned int t2 = s.size;
111 unsigned int t3 = s.cap; 111 unsigned int t3 = s.cap;
examples11/05-foldexpr/vector.h
@@ -11,7 +11,7 @@ template &lt;class C&gt; class vector { @@ -11,7 +11,7 @@ template &lt;class C&gt; class vector {
11 11
12 private: 12 private:
13 static unsigned int round_up_to_power_of_2(unsigned w) { 13 static unsigned int round_up_to_power_of_2(unsigned w) {
14 - const auto bits = std::numeric_limits<unsigned>::digits; 14 + constexpr auto bits = std::numeric_limits<unsigned>::digits;
15 --w; 15 --w;
16 for (unsigned s = 1; s < bits; s *= 2) 16 for (unsigned s = 1; s < bits; s *= 2)
17 w |= w >> s; 17 w |= w >> s;
@@ -105,7 +105,7 @@ public: @@ -105,7 +105,7 @@ public:
105 } 105 }
106 } 106 }
107 107
108 - void swap(vector<C> &s) { 108 + void swap(vector<C> &s) noexcept {
109 C *t1 = s.data; 109 C *t1 = s.data;
110 unsigned int t2 = s.size; 110 unsigned int t2 = s.size;
111 unsigned int t3 = s.cap; 111 unsigned int t3 = s.cap;
examples11/06-template_metaprogramming/vector.h
@@ -12,7 +12,7 @@ template &lt;class C&gt; class vector { @@ -12,7 +12,7 @@ template &lt;class C&gt; class vector {
12 12
13 private: 13 private:
14 static unsigned int round_up_to_power_of_2(unsigned w) { 14 static unsigned int round_up_to_power_of_2(unsigned w) {
15 - const auto bits = std::numeric_limits<unsigned>::digits; 15 + constexpr auto bits = std::numeric_limits<unsigned>::digits;
16 --w; 16 --w;
17 for (unsigned s = 1; s < bits; s *= 2) 17 for (unsigned s = 1; s < bits; s *= 2)
18 w |= w >> s; 18 w |= w >> s;
@@ -110,7 +110,7 @@ public: @@ -110,7 +110,7 @@ public:
110 } 110 }
111 } 111 }
112 112
113 - void swap(vector<C> &s) { 113 + void swap(vector<C> &s) noexcept {
114 C *t1 = s.data; 114 C *t1 = s.data;
115 unsigned int t2 = s.size; 115 unsigned int t2 = s.size;
116 unsigned int t3 = s.cap; 116 unsigned int t3 = s.cap;