Commit c7fae41f51100c8939cff8001ca53bff03aa94b3
1 parent
a773e56f
constexpr and noexcept in vector template
Showing
3 changed files
with
6 additions
and
6 deletions
examples11/04-vectortmpl/vector.h
... | ... | @@ -11,7 +11,7 @@ template <class C> class vector { |
11 | 11 | |
12 | 12 | private: |
13 | 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 | 15 | --w; |
16 | 16 | for (unsigned s = 1; s < bits; s *= 2) |
17 | 17 | w |= w >> s; |
... | ... | @@ -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 | 109 | C *t1 = s.data; |
110 | 110 | unsigned int t2 = s.size; |
111 | 111 | unsigned int t3 = s.cap; | ... | ... |
examples11/05-foldexpr/vector.h
... | ... | @@ -11,7 +11,7 @@ template <class C> class vector { |
11 | 11 | |
12 | 12 | private: |
13 | 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 | 15 | --w; |
16 | 16 | for (unsigned s = 1; s < bits; s *= 2) |
17 | 17 | w |= w >> s; |
... | ... | @@ -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 | 109 | C *t1 = s.data; |
110 | 110 | unsigned int t2 = s.size; |
111 | 111 | unsigned int t3 = s.cap; | ... | ... |
examples11/06-template_metaprogramming/vector.h
... | ... | @@ -12,7 +12,7 @@ template <class C> class vector { |
12 | 12 | |
13 | 13 | private: |
14 | 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 | 16 | --w; |
17 | 17 | for (unsigned s = 1; s < bits; s *= 2) |
18 | 18 | w |= w >> s; |
... | ... | @@ -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 | 114 | C *t1 = s.data; |
115 | 115 | unsigned int t2 = s.size; |
116 | 116 | unsigned int t3 = s.cap; | ... | ... |