Do I really need to return Type :: size_type?

I often have classes that basically just wrap around some STL container, for example:

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

I am not sure about the return size_type. Often some function calls size()and passes this value to another function, and it will use it and, possibly, pass it. Now everyone should include this Foo header, although I really just pass some size value, which should just be unsigned intanyway ...? What is the right thing here? Is it better to use size_typeeverywhere?

+3
source share
5 answers

STL . . NUMA , size_type ptr-type . - NUMA - node, size_type ptr_type - .

, , , , ++. STL, , STL, . , , , STL .

, ? .

+7

vector<>::size_type, , .

, , , , size_t. , vector<>::size_type size_t , . .

+6

, size_t, unsigned int, 64- . -, size_type. , (size_t), .

+5

size_type. call size() , , . Foo...

size_type, , size_type, . . size_t.

, , size , deque .., , size_type ( , , ). - , , size_type .

+1

, , std::vector:

typedef std::vector<whatever> Foo_Vec;

class Foo : public Foo_Vec
{
public:
    const Foo_Vec &GetVec() { return (Foo_Vec&)*this; }
};

, , , private Foo_Vec, public Foo_Vec std::vector Foo. , std::vector , , std::vector Foo, . .

, size_t size_type unsigned int 64- . 64- std::vector 2 32 , .

-1
source

Source: https://habr.com/ru/post/1742333/


All Articles