#include <array>
#include <cmath>
#include <iostream>
using namespace std;
template <typename T, int Size>
class Vector {
public:
Vector() = default;
~Vector() = default;
// gcc - срабатывает static_assert (которые перед main-ом)
// clang - все нормально
// template <typename... Args>
// Vector(const Args... args)
// : values { args... } {
// static_assert(sizeof...(args) == Size, "Vector::Vector -- wrong number of arguments");
// }
// Оба компилятора считают это, хорошим, годным кодом.
template<int S, typename... Args>
Vector(const Vector<T, S>& vector, const Args... args) {
static_assert((sizeof...(args) + S) == Size, "Vector::Vector -- wrong number of arguments");
// Говнокод, но не суть
const array<T, sizeof...(args)> tmp { args... };
copy(vector.values.begin(), vector.values.end(), values.begin());
copy(tmp.begin(), tmp.end(), values.begin() + S);
}
private:
array<T, Size> values;
};
using Vector2f = Vector<float, 2>;
// вот этот
static_assert(is_pod<Vector2f>::value, "Vector<T, Size> should be a POD");
int main() {
return 0;
}
Вопрос в том, чем этот конструктор такой особенный? Ну и что делать, да.
Вроде если класс удовлетворяет списку ниже, то он POD.
- Has a trivial default constructor. This may use the default constructor syntax (SomeConstructor() = default;).
- Has trivial copy and move constructors, which may use the default syntax.
- Has trivial copy and move assignment operators, which may use the default syntax.
- Has a trivial destructor, which must not be virtual.
- It has no virtual functions
- It has no virtual base classes
- All its non-static data members have the same access control (public, private, protected)
- All its non-static data members, including any in its base classes, are in the same one class in the hierarchy
- The above rules also apply to all the base classes and to all non-static data members in the class hierarchy
- It has no base classes of the same type as the first defined non-static data member
То есть gcc-ня приняла этот конструктор за конструктор копирования/перемещения?
gcc 4.8.2 (Ubuntu 4.8.2-19ubuntu1)
clang 3.4-1ubuntu3