C++ std::array reimplementation [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
-1
down vote

favorite












As a conceptual implementation of the default c++ std array interface, would this be a suitable implementation & what is the safety of this implementation?



template<typename T> 
class Array

private:
T* arr;
public:
Array(const size_t size)

arr = (T*)malloc(sizeof(T) * size);

~Array()

free(arr);

T& operator(size_t index) const

return arr[index];

;






share|improve this question











closed as off-topic by Incomputable, Stephen Rauch, JDługosz, Billal BEGUERADJ, Raystafarian Jun 11 at 4:14


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Incomputable, JDługosz, Billal BEGUERADJ, Raystafarian
If this question can be reworded to fit the rules in the help center, please edit the question.












  • There’s an issue here also if T requires initialization (i.e. it’s something different from a numeric type).
    – Cris Luengo
    Jun 11 at 1:07
















up vote
-1
down vote

favorite












As a conceptual implementation of the default c++ std array interface, would this be a suitable implementation & what is the safety of this implementation?



template<typename T> 
class Array

private:
T* arr;
public:
Array(const size_t size)

arr = (T*)malloc(sizeof(T) * size);

~Array()

free(arr);

T& operator(size_t index) const

return arr[index];

;






share|improve this question











closed as off-topic by Incomputable, Stephen Rauch, JDługosz, Billal BEGUERADJ, Raystafarian Jun 11 at 4:14


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Incomputable, JDługosz, Billal BEGUERADJ, Raystafarian
If this question can be reworded to fit the rules in the help center, please edit the question.












  • There’s an issue here also if T requires initialization (i.e. it’s something different from a numeric type).
    – Cris Luengo
    Jun 11 at 1:07












up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











As a conceptual implementation of the default c++ std array interface, would this be a suitable implementation & what is the safety of this implementation?



template<typename T> 
class Array

private:
T* arr;
public:
Array(const size_t size)

arr = (T*)malloc(sizeof(T) * size);

~Array()

free(arr);

T& operator(size_t index) const

return arr[index];

;






share|improve this question











As a conceptual implementation of the default c++ std array interface, would this be a suitable implementation & what is the safety of this implementation?



template<typename T> 
class Array

private:
T* arr;
public:
Array(const size_t size)

arr = (T*)malloc(sizeof(T) * size);

~Array()

free(arr);

T& operator(size_t index) const

return arr[index];

;








share|improve this question










share|improve this question




share|improve this question









asked Jun 10 at 23:10









James

1




1




closed as off-topic by Incomputable, Stephen Rauch, JDługosz, Billal BEGUERADJ, Raystafarian Jun 11 at 4:14


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Incomputable, JDługosz, Billal BEGUERADJ, Raystafarian
If this question can be reworded to fit the rules in the help center, please edit the question.




closed as off-topic by Incomputable, Stephen Rauch, JDługosz, Billal BEGUERADJ, Raystafarian Jun 11 at 4:14


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Incomputable, JDługosz, Billal BEGUERADJ, Raystafarian
If this question can be reworded to fit the rules in the help center, please edit the question.











  • There’s an issue here also if T requires initialization (i.e. it’s something different from a numeric type).
    – Cris Luengo
    Jun 11 at 1:07
















  • There’s an issue here also if T requires initialization (i.e. it’s something different from a numeric type).
    – Cris Luengo
    Jun 11 at 1:07















There’s an issue here also if T requires initialization (i.e. it’s something different from a numeric type).
– Cris Luengo
Jun 11 at 1:07




There’s an issue here also if T requires initialization (i.e. it’s something different from a numeric type).
– Cris Luengo
Jun 11 at 1:07










1 Answer
1






active

oldest

votes

















up vote
1
down vote













The code you provided is more like a vector rather than an array. An array's size is specified at compile-time (is fixed). Hence the most basic implementation would be:



#include <cstddef>

template<typename type, std::size_t size>
struct array

type data[size];
;





share|improve this answer




























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    The code you provided is more like a vector rather than an array. An array's size is specified at compile-time (is fixed). Hence the most basic implementation would be:



    #include <cstddef>

    template<typename type, std::size_t size>
    struct array

    type data[size];
    ;





    share|improve this answer

























      up vote
      1
      down vote













      The code you provided is more like a vector rather than an array. An array's size is specified at compile-time (is fixed). Hence the most basic implementation would be:



      #include <cstddef>

      template<typename type, std::size_t size>
      struct array

      type data[size];
      ;





      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        The code you provided is more like a vector rather than an array. An array's size is specified at compile-time (is fixed). Hence the most basic implementation would be:



        #include <cstddef>

        template<typename type, std::size_t size>
        struct array

        type data[size];
        ;





        share|improve this answer













        The code you provided is more like a vector rather than an array. An array's size is specified at compile-time (is fixed). Hence the most basic implementation would be:



        #include <cstddef>

        template<typename type, std::size_t size>
        struct array

        type data[size];
        ;






        share|improve this answer













        share|improve this answer



        share|improve this answer











        answered Jun 11 at 0:25









        demiralp

        436




        436












            Popular posts from this blog

            Python Lists

            Aion

            JavaScript Array Iteration Methods