Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.4 KiB

  1. %{
  2. #include <algorithm>
  3. %}
  4. //
  5. // std::carray - is really an extension to the 'std' namespace.
  6. //
  7. // A simple fix C array wrapper, more or less as presented in
  8. //
  9. // "The C++ Standarf Library", by Nicolai M. Josuttis
  10. //
  11. // which is also derived from the example in
  12. //
  13. // "The C++ Programming Language", by Bjarne Stroustup.
  14. //
  15. %inline %{
  16. namespace std {
  17. template <class _Type, size_t _Size>
  18. class carray
  19. {
  20. public:
  21. typedef _Type value_type;
  22. typedef size_t size_type;
  23. typedef _Type * iterator;
  24. typedef const _Type * const_iterator;
  25. carray() { }
  26. carray(const carray& c) {
  27. std::copy(c.v, c.v + size(), v);
  28. }
  29. template <class _Iterator>
  30. carray(_Iterator first, _Iterator last) {
  31. assign(first, last);
  32. }
  33. iterator begin() { return v; }
  34. iterator end() { return v + _Size; }
  35. const_iterator begin() const { return v; }
  36. const_iterator end() const { return v + _Size; }
  37. _Type& operator[](size_t i) { return v[i]; }
  38. const _Type& operator[](size_t i) const { return v[i]; }
  39. static size_t size() { return _Size; }
  40. template <class _Iterator>
  41. void assign(_Iterator first, _Iterator last) {
  42. if (std::distance(first,last) == size()) {
  43. std::copy(first, last, v);
  44. } else {
  45. throw std::length_error("bad range length");
  46. }
  47. }
  48. private:
  49. _Type v[_Size];
  50. };
  51. }
  52. %}