Writing an own string class

Discussion in 'C++' started by Tony Winslow, Jul 5, 2008.

  1. Tony Winslow

    Tony Winslow Guest

    Hi, there!

    Some users of this group mentioned before that
    being able to write one's own string class in
    C++ is a sign of mastering the basics of the
    language. My problem is that I don't quite
    understand how does that work. I mean writing a
    string class is not very hard, but how can I
    determine the string class is working properly
    enough or even efficient enough? What is the
    benchmark thing that I can use?

    Tony Winslow
     
    Tony Winslow, Jul 5, 2008
    #1
    1. Advertising

  2. On 2008-07-05 17:28, Tony Winslow wrote:
    > Hi, there!
    >
    > Some users of this group mentioned before that
    > being able to write one's own string class in
    > C++ is a sign of mastering the basics of the
    > language. My problem is that I don't quite
    > understand how does that work. I mean writing a
    > string class is not very hard, but how can I
    > determine the string class is working properly
    > enough or even efficient enough? What is the
    > benchmark thing that I can use?


    The requirements on strings are not universally agreed upon, different
    people have different requirements. If you can not come up with the
    requirements yourself you can look at some existing implementations
    (like std::string, QString, etc.). The same goes for performance, find
    an implementation with similar functionality to yours and devise some
    benchmarks to compare them, or look up some existing benchmarks.

    --
    Erik Wikström
     
    Erik Wikström, Jul 5, 2008
    #2
    1. Advertising

  3. Tony Winslow

    osmium Guest

    "Tony Winslow" writes:

    > Some users of this group mentioned before that
    > being able to write one's own string class in
    > C++ is a sign of mastering the basics of the
    > language. My problem is that I don't quite
    > understand how does that work. I mean writing a
    > string class is not very hard, but how can I
    > determine the string class is working properly
    > enough or even efficient enough? What is the
    > benchmark thing that I can use?


    You write your own tests as you go along, starting with the fundamentals and
    eventually testing for all the corner cases you can think of. Then release
    it to the wild Off the top of my head, and probably with errors something
    like this:

    Your string class is String. '+' is concatenate. Include a show() function
    in as a test device.

    String S s("abc");
    s.show();
    ----
    String S t();
    t.show();
    ----
    modifies x
    void f(&S x) { }
    ....
    String S u("abc");
    u.show();
    ----
    String S d("abc", e("def");
    d = e + d;
    d.show();
    ---
    String S a("abc"), b, c;

    c = b= a;
    ____
    Something with arrays of strings. Vectors of strings. Prove it is STL
    friendly by sorting your strings. And so on.
     
    osmium, Jul 5, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Siegl
    Replies:
    1
    Views:
    777
  2. E11
    Replies:
    1
    Views:
    4,800
    Thomas Weidenfeller
    Oct 12, 2005
  3. matthurne
    Replies:
    3
    Views:
    946
    matthurne
    Jul 22, 2004
  4. Saverio M.
    Replies:
    0
    Views:
    527
    Saverio M.
    Jul 3, 2006
  5. David Filmer
    Replies:
    17
    Views:
    270
    J. Romano
    Aug 18, 2004
Loading...

Share This Page