Commit c4956ef982b8b78d66001cab79bddf18dfdcc313

Authored by Grzegorz Jabłoński
1 parent 45c0f87a

Conditional std::move depending on noexcept

examples11/04-vectortmpl/vector.h
... ... @@ -38,8 +38,11 @@ private:
38 38 unsigned i;
39 39 try {
40 40 for (i = 0; i < size; i++)
41   -// new (newdata + i) C(std::move(data[i]));
42   - new (newdata + i) C(data[i]);
  41 + if constexpr (noexcept(C(std::move(data[i])))) {
  42 + // cout << "noexcept" << endl;
  43 + new (newdata + i) C(std::move(data[i]));
  44 + } else
  45 + new (newdata + i) C(data[i]);
43 46 } catch (...) {
44 47 destroy_array(newdata, i);
45 48 throw;
... ...
examples11/05-foldexpr/vector.h
... ... @@ -38,8 +38,11 @@ private:
38 38 unsigned i;
39 39 try {
40 40 for (i = 0; i < size; i++)
41   - new (newdata + i) C(data[i]);
42   -// new (newdata + i) C(std::move(data[i]));
  41 + if constexpr (noexcept(C(std::move(data[i]))))
  42 + new (newdata + i) C(std::move(data[i]));
  43 + else
  44 + new (newdata + i) C(data[i]);
  45 +
43 46 } catch (...) {
44 47 destroy_array(newdata, i);
45 48 throw;
... ...
examples11/06-template_metaprogramming/vector.h
... ... @@ -36,8 +36,11 @@ private:
36 36 unsigned i;
37 37 try {
38 38 for (i = 0; i < size; i++)
39   - new (newdata + i) C(data[i]);
40   -// new (newdata + i) C(std::move(data[i]));
  39 + if constexpr (noexcept(C(std::move(data[i]))))
  40 + new (newdata + i) C(std::move(data[i]));
  41 + else
  42 + new (newdata + i) C(data[i]);
  43 +
41 44 } catch (...) {
42 45 destroy_array(newdata, i);
43 46 throw;
... ... @@ -148,7 +151,6 @@ public:
148 151 }
149 152  
150 153 private:
151   -
152 154 public:
153 155 void reserve(unsigned capacity) {
154 156 if (capacity > std::numeric_limits<decltype(size)>::max() / (2 * sizeof(C)))
... ...