Should I return an iterator or pointer to an element in the STL container?

I am developing a mechanism for porting existing code to another platform. Existing code was developed using a third-party API, and my engine will override the functions of third-party APIs in terms of my new platform.

The following definitions are used in the API:

typedef unsigned long shape_handle;    
shape_handle make_new_shape( int type );

I need to override make_new_shape, and I have the ability to override shape_handle.

I defined this structure (simplified):

struct Shape
{
    int type
};

Caller make_new_shapedoes not care about the basic structure Shape, he just needs a “handle” so that he can call functions such as:

void `set_shape_color( myshape, RED );`

where myshapeis the form handle.

Shape, , Shape .

: - Shape std:: list - , , ?

+5
4

:

  • std::list iterator ( ), iterator , .
  • std::map boost::unordered_map, Key ()

, , , Undefined Behavior.

map, unordered_map, , :)

+3

, , , . , .

, , . , .

, std:: list [].

+6

IIF Shapes, . , . . O (n) .

, , , , / .

, , (/) . , Shape .

+3

, , , , STL!

, , , , . , , , , - . , .

, STL, , , , " ". , , . Boom, .

So, not indexes for O (n) performance. There are always iterators between pointers and iterators!

+3
source

All Articles