General Purpose library for Freestanding C++ and POSIX systems
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.

71 rivejä
1.2 KiB

4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
  1. #pragma once
  2. #include <initializer_list>
  3. #include <gp/buffer.hpp>
  4. namespace gp{
  5. template<typename T, std::size_t sz>
  6. class array{
  7. T ary[sz];
  8. public:
  9. using associated_iterator = pointer_iterator<T>;
  10. using associated_const_iterator = pointer_iterator<T>;
  11. array() = default;
  12. template<typename ...U>
  13. array(U&& ...v)
  14. : ary{gp::forward(v...)}
  15. {}
  16. constexpr T& operator[] (size_t off)
  17. {
  18. return ary[off];
  19. }
  20. constexpr size_t size() const
  21. {
  22. return sz;
  23. }
  24. constexpr associated_iterator begin()
  25. {
  26. return associated_iterator(&ary[0]);
  27. }
  28. constexpr associated_iterator end()
  29. {
  30. return associated_iterator(&ary[sz]);
  31. }
  32. constexpr associated_const_iterator cbegin() const
  33. {
  34. return ary;
  35. }
  36. constexpr associated_const_iterator cend() const
  37. {
  38. return ary+sz;
  39. }
  40. constexpr bool operator==(const array& oth) const
  41. {
  42. for(size_t idx = 0; idx<sz; idx++)
  43. {
  44. if(ary[idx] != oth.ary[idx])
  45. {
  46. return false;
  47. }
  48. }
  49. return true;
  50. }
  51. constexpr bool operator!=(const array& oth) const
  52. {
  53. return !(*this == oth);
  54. }
  55. gp::buffer<T> as_buffer()
  56. {
  57. return gp::buffer<T>{(T*)ary, (T*)ary+sz};
  58. }
  59. };
  60. }