Do I really need to return Type::size_type?

Posted by dehmann on Stack Overflow See other posts from Stack Overflow or by dehmann
Published on 2010-04-22T19:05:46Z Indexed on 2010/04/22 19:13 UTC
Read the original article Hit count: 101

Filed under:
|
|

I often have classes that are mostly just wrappers around some STL container, like this:

class Foo {
public:
  typedef std::vector<whatever> Vec;
  typedef Vec::size_type;
  const Vec& GetVec() { return vec_; }
  size_type size() { return vec_.size() }
private:
  Vec vec_;
};

I am not so sure about returning size_type. Often, some function will call size() and pass that value on to another function and that one will use it and maybe pass it on. Now everyone has to include that Foo header, although I'm really just passing some size value around, which should just be unsigned int anyway ...? What is the right thing to do here? Is it best practice to really use size_type everywhere?

© Stack Overflow or respective owner

Related posts about c++

Related posts about size-type