fork download
  1.  
  2. #include <array>
  3. #include <functional>
  4.  
  5.  
  6. /// vector.h
  7. template <typename NumType, unsigned char Size>
  8. class Vector
  9. {
  10. public:
  11. using CoordType = NumType;
  12.  
  13. //Vector(const Vector& v) : values(v.values) {}
  14. //Vector(Vector&& v) : values(std::move(v.values)) {}
  15.  
  16. template<typename... NumTypes>
  17. constexpr Vector(NumTypes&&... vals) : values{ std::forward<NumTypes>(vals)... }
  18. {
  19. static_assert(sizeof...(NumTypes) == Size, "You must provide N arguments.");
  20. }
  21.  
  22. Vector(const std::array<NumType, Size>& values) : values(values) {}
  23. Vector(std::array<NumType, Size>&& values) : values(std::move(values)) {}
  24.  
  25. const NumType& operator[](size_t offset) const { return values[offset]; }
  26. NumType& operator[](size_t offset) { return values[offset]; }
  27. //Vector& operator=(const Vector& other) { values = other.values; }
  28. //Vector& operator=(Vector&& other) { values = std::move(other.values); }
  29.  
  30. std::array<NumType, Size> values;
  31.  
  32. };
  33. /// END vector.h
  34.  
  35. using Vector3Int = Vector<int, 3>;
  36. int main() {
  37. Vector3Int test {1,2,3};
  38. Vector3Int test2 = test;
  39.  
  40. return 0;
  41. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘constexpr Vector<NumType, Size>::Vector(NumTypes&& ...) [with NumTypes = {Vector<int, 3>&}; NumType = int; unsigned char Size = 3]’:
prog.cpp:38:21:   required from here
prog.cpp:17:82: error: cannot convert ‘Vector<int, 3>’ to ‘int’ in initialization
   constexpr Vector(NumTypes&&... vals) : values{ std::forward<NumTypes>(vals)... }
                                                                                  ^
prog.cpp:19:39: error: static assertion failed: You must provide N arguments.
     static_assert(sizeof...(NumTypes) == Size, "You must provide N arguments.");
                   ~~~~~~~~~~~~~~~~~~~~^~~~~~~
stdout
Standard output is empty